News for hackers. Stuff that matters.
Re:What Every C Programmer Should Know About Undefined Behav... by aargh_aargh on Thursday January 05, 2017 @04:38AM (#13325923)
Since I didn't get the reference, here's the explanation:

http://catb.org/jargon/html/N/nasal-demons.html

Re:What Every C Programmer Should Know About Undefined Behav... by mattkrause on Thursday January 05, 2017 @10:32AM (#13327883)
I love the mental image, but I think that description masks why this happening.

The compiler doesn't specifically search for undefined behavior and use it as an excuse to do something "quirky." Instead, it assumes the code is well-defined and interprets (and transforms) it in ways that preserve its semantics. For example, "One cannot dereference null pointers. The author dereferenced the pointer p. Therefore, p is not null. Since p is not null, the compiler can avoid checking it after the first dereference." The compiler is essentially assuming that the author knows something that it may not and just runs with it.

However, there are a lot of transformations--and corner cases--many of which can interact. This can produce complex unwanted behavior that looks like "nasal demons", but largely as a side effect. The compiler does not say "OVERFLOW DETECTED. REPLACING ENTIRE FUNCTION WITH NOOP"