LWN.net Logo

What every C Programmer should know about undefined behavior #2/3

What every C Programmer should know about undefined behavior #2/3

Posted May 17, 2011 8:40 UTC (Tue) by marcH (subscriber, #57642)
In reply to: What every C Programmer should know about undefined behavior #2/3 by gowen
Parent article: What every C Programmer should know about undefined behavior #2/3

I think the main issue is having a dead variable in the first place. If "dead" is not dead, then there is no problem, correct?


(Log in to post comments)

What every C Programmer should know about undefined behavior #2/3

Posted May 17, 2011 14:55 UTC (Tue) by nye (guest, #51576) [Link]

>If "dead" is not dead, then there is no problem, correct?

Incorrect - it's not a result of dead code elimination. This bug arises even if dead is used for something later on, because the initial assignment invokes undefined behaviour in the case that P is NULL. It's therefore always conformant for the compiler to assume that P is *not* NULL and remove the check, since if that assumption is incorrect then the behaviour is undefined and the compiler can do whatever it damn well pleases.

Copyright © 2013, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds