[Bug c/47732] counter decremented to zero not detected when other counter overflows

J.K.Annot.at.Infor at gmail dot com gcc-bugzilla@gcc.gnu.org
Tue Feb 15 14:25:00 GMT 2011


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47732

--- Comment #2 from Jan Koen Annot <J.K.Annot.at.Infor at gmail dot com> 2011-02-15 14:21:16 UTC ---
(In reply to comment #1)
> And overflow is undefined in C/C++ so you are invoking undefined behavior here.

Wow! This is an eye-opener for me! I am quite accustomed to assume two's
complement arithmetic with implicit wrap-around for signed integers.

After your remark I googled a bit and found several articles about undefined
behavior, e.g. John Regehr's "A Guide to Undefined Behavior in C and C++, Part
1".
Very instructive.



More information about the Gcc-bugs mailing list