As you know, signed integer overflow is undefined behavior . But there is something interesting in the C ++ 11 cstdint documentation:
with an integer type sign with a width of exactly 8, 16, 32 and 64 bits, respectively, without padding bits and using 2 additions for negative values (if only the implementation directly supports the type)
See link
And here is my question: since the standard explicitly states that for int8_t , int16_t , int32_t and int64_t negative numbers are 2 additions, do these types still overflow with a undefined behavior?
Edit I checked the C ++ 11 and C11 standards, and here is what I found:
C ++ 11, Β§18.4.1:
The header defines all functions, types and macros in the same way as 7.20 in the C standard.
C11, Β§7.20.1.1:
The name typedef intN_t denotes an integer type with a sign with a width of N, no padding bits, and a double padding representation. Thus, int8_t denotes such a signed integer type with a width of exactly 8 bits.
c ++ undefined-behavior c ++ 11 integer-overflow
Archie Apr 24 '13 at 9:24 2013-04-24 09:24
source share