It's a well-known fact that signed integer overflow invokes undefined behavior, and that bitwise manipulation of signed integers is unreliable at best. Thus, I found this line in the POSIX standard rather curious:
The typedef name int N _t designates a signed integer type with width N, no padding bits, and a two's-complement representation. Thus, int8_t denotes a signed integer type with a width of exactly 8 bits.
This is a rather nebulous statement, which could mean any combination of these things:
- The range of
intN_tis fromINTN_MINtoINTN_MAX. sizeof(intN_t) == N/8- Bitwise operations on
intN_tbehave as expected for a two's complement representation.-1 ^ x == ~xfor everyx, after insertingintN_tcasts everywhere. intN_tcannot have trap representations (and an optimizing compiler must not exploit possible traps).- Overflow of an
intN_tvariable is defined behavior (and wraps fromINTN_MAXtoINTN_MIN).
(1) and (2) both seem pretty obviously true to me, based on the rest of the document. (1) is explicitly specified by the definition of INTN_MIN/MAX. (2) is implied by "no padding bits."
Which of (3), (4), and (5) are required by POSIX, if any?