Why is this undefined behavior when I always get the same result?-Record and share programming errors
“Undefined” means that the standard doesn’t specify what has to happen in that situation, so anything your compiler does is, by definition, right. If it always prints 01
, that’s fine. If it prints a different number every time you run, that would be fine too. If it causes monkeys to fly out of your nose (as illustrated here), that would be fine as well.
You might not think so, but the compiler writers are off the hook if it happens.
[Edit: It has been pointed out in the comments that the cannonical reference is “nasal demons”, not “nasal monkeys”. My apologies for any unintended confusion. Any intended confusion I’m proud of and do not apologize for. 🙂 ]
Originally posted 2013-08-31 05:39:39.