What does POSIX mean by "two's complement representation" in stdint.h?

Viewed 383

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:

  1. The range of intN_t is from INTN_MIN to INTN_MAX.
  2. sizeof(intN_t) == N/8
  3. Bitwise operations on intN_t behave as expected for a two's complement representation. -1 ^ x == ~x for every x, after inserting intN_t casts everywhere.
  4. intN_t cannot have trap representations (and an optimizing compiler must not exploit possible traps).
  5. Overflow of an intN_t variable is defined behavior (and wraps from INTN_MAX to INTN_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?

1 Answers
Related