4 ms·
Yes, signed overflow can make f+1 > f be false. However in C/C++, because signed overflow is undefined behavior, the compiler is perfectly allowed to simplify t
by nayuki 7y ago
Yes, signed overflow can make f+1 > f be false. However in C/C++, because signed overflow is undefined behavior, the compiler is perfectly allowed to simplify the expression f+1 > f to always be true.
- stephencanon 7y agoThe compiler can make that simplification, but there's no guarantee that every compiler does, so you cannot assume that it will do so; it will sometimes happen to be true in a specific compiler, but it is never true in the standardized language model (which is what programs are written against).
- yoz-y 7y agoWhich would then have the same effect as the title's article, a bug with -O0 but working with -O3
- BubRoss 7y agoIt _could_ have that effect, but it would depend on signed integers wrapping.
- kbp 7y agoUnsigned integers are still specified to wrap.