What are the size guarantees on int
in Single UNIX or POSIX? This sure is a FAQ, but I can't find the answer...
With icecrime's answer, and a bit further searching on my side, I got a complete picture:
ANSI C and C99 both mandate that INT_MAX be at least +32767 (i.e. 2^15-1). POSIX doesn't go beyong that. Single Unix v1 has the same guarantee, while Single Unix v2 states that the minimum acceptable value is 2 147 483 647 (i.e. 2^31-1).
The C99 standard specifies the content of header <limits.h>
in the following way :
Their implementation-defined values shall be equal or greater in magnitude (absolute value) to those shown, with the same sign.
- minimum value for an object of type int
INT_MIN -32767
// -(215 - 1)- maximum value for an object of type int
INT_MAX +32767
// 215 - 1- maximum value for an object of type unsigned int
UINT_MAX 65535
// 216 - 1
There are no size requirements expressed on the int
type.
However, the <stdint.h>
header offer the additional exact-width integer types int8_t
, int16_t
, int32_t
, int64_t
and their unsigned counterpart :
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.
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