Is the int16_t
type declared in <stdint.h>
guaranteed to be signed, or is it just supposed to be signed? I would assume that it would have to be signed, but surprisingly I can't seem to find any hard evidence (i.e. references to the spec) that explicitly mention this anywhere.
Could someone confirm this either way? I'd really appreciate specific references to the spec, if at all possible.
n1256 7.18.1p1 says:
When typedef names differing only in the absence or presence of the initial u are defined, they shall denote corresponding signed and unsigned types as described in 6.2.5; an implementation providing one of these corresponding types shall also provide the other.
Since there is an int16_t
and a uint16_t
, the int16_t
is therefore signed.
Or indeed 7.18.1.1p1:
The typedef name intN_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.
which is more explicit about it.
EDIT: although strictly speaking, int16_t is not guaranteed to be signed in the sense that it's not guaranteed to exist. If you have CHAR_BIT==9, for example, there cannot be a int16_t
type.
Yes, int16_t is guaranteed to be signed two's complement by the ISO spec.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With