4 ms·
>And, maaaaaaybe signed integer overflow. Overflow checking is sometimes done like this (where a is a signed integer): if (a + 100 < a) ... Of course this
by Kristine1975 11y ago
>And, maaaaaaybe signed integer overflow.
Overflow checking is sometimes done like this (where a is a signed integer):
if (a + 100 < a) ...
Of course this invokes undefined behavior, and some people get angry when compilers remove the check: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=30475 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=30475
- anttihaapala 11y agoAnd of course the code is wrong, because the behaviour is undefined - in 64-bit architectures it is very common to use 64-bit registers for `int` even if in memory `sizeof(int) == 4`; thus `int a = INT_MAX;`, `a + 100` could still be greater than `INT_MAX`.