Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Guarantees on sizeof(int) in Single UNIX or POSIX

Tags:

unix

posix

sizeof

What are the size guarantees on int in Single UNIX or POSIX? This sure is a FAQ, but I can't find the answer...

like image 773
F'x Avatar asked Dec 26 '10 12:12

F'x


2 Answers

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).

like image 113
F'x Avatar answered Sep 17 '22 22:09

F'x


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.

like image 34
icecrime Avatar answered Sep 20 '22 22:09

icecrime