What Every C Programmer Should Know About Undefined Behavior #3/3
Posted May 23, 2011 6:54 UTC (Mon) by iabervon
In reply to: What Every C Programmer Should Know About Undefined Behavior #3/3
Parent article: What Every C Programmer Should Know About Undefined Behavior #3/3
The usual problem is that programmers assume that, while something is undefined, it is within some limited range. For example, people assume that dereferencing a pointer leads to either a trap or some arbitrary value; they are surprised if it leads to some later well-defined code not behaving as defined.
For that matter, the OpenSSL developers assume that uninitialized variables contain unspecified values of their types (rather than accessing them causing undefined behavior). If a compiler were to use a special "undef" value such that any operation that used it produced "undef", and constant-propagated this through the random number generator, it would find that the random number generator always produces "undef", and could strip it out entirely.
There's a lot of cases where programmers imagine what undefined behavior a compiler could find useful to pick for their code, and the programmers are fine with any choice they can imagine. But their imaginations are not nearly good enough.
to post comments)