Re:When you see a Heisenbug in C, change your compiler's opt...
by theseoafs on Sunday March 02, 2014 @03:09AM
(#7328232)
Why would you expect the NULL pointer check to do anything? The function, as given, is meaningless if `p` is NULL. The problem isn't that compilers are too aggressive in their optimization -- the problem is that people who are learning C don't usually learn what it means for the behavior of a program to be undefined.
Re:When you see a Heisenbug in C, change your compiler's opt...
by userbinator on Sunday March 02, 2014 @12:18AM
(#7327821)
> If x is unused, the compiler is allowed to remove the assignment
This and the Apple SSL bug makes me think that optimising compilers should be far more explicit (i.e. emitting messages or even warnings) about what they're doing than they are now, because it seems far too much about the optimisation process is being hidden and not transparent enough. Not only unreachable code, messages like "result of computation x is never used", "if-condition assumed to be {false, true}", "while-loop condition always false - body removed", etc. would be extremely useful for detecting and fixing these problems.
http://blog.llvm.org/2011/05/what-every-c-programmer-should-...
Please read that article, and the rest in the series. Undefined behavior is far more pervasive than you think.