Here's a good article that addresses the question "Why have undefined behavior?"
http://blog.regehr.org/archives/213
This one linking to the above is also worth reading:
http://blog.llvm.org/2011/05/what-every-c-programmer-should-...
Here's a good article that addresses the question "Why have undefined behavior?"
http://blog.regehr.org/archives/213
This one linking to the above is also worth reading:
http://blog.llvm.org/2011/05/what-every-c-programmer-should-...
I always imagined undefined behaviour was there to avoid tying implementations' hands, by having the standard not mandate things that vary in practice. But it seems that people are assuming it's there to give compiler writers carte blanche to do whatever they like, and then point at the standard as justification. Given how much stuff could potentially be added to C to improve it, I don't know why people are spending all this time trying to figure out all the ways in which the letter of the law allows them to confuse the programmer.
See also somebody else's rant about strict aliasing: http://robertoconcerto.blogspot.co.uk/2010/10/strict-aliasin...