ISO / IEC 9899: 1999 (C99) adds the headers <stdint.h> and <inttypes.h> , which provide what you need:
int16_t cannot be defined, but if the implementation has a 16-bit (exactly) integer type, int16_t will be an alias for it.int_least16_t is a type that is the smallest type that contains at least 16 bits. He is always available.int_fast16_t is the fastest type that contains at least 16 bits. He is always available.
Similarly for other sizes: 8, 16, 32, 64.
Here is also intmax_t for an integer type of maximum precision. Of course, for each of them there is also an unsigned type: uint16_t , etc.
These types are also present in C2011. They were not present on the C89 or C90. However, I believe that headers are available in some form or form for most compilers, even those such as MS Visual C, which do not pretend to support C99.
Please note that I have provided links to the POSIX 2008 versions of the headers <stdint.h> and <inttypes.h> . POSIX imposes implementation rules that are not in the C standard:
Β§7.18.1.1 Integer types of exact width
ΒΆ1 The name typedef int N _t denotes a signed integer type with a width of N, without filling in bits, and representing a double complement. Thus int8_t denotes a signed integer type with a width of exactly 8 bits.
ΒΆ2 Typedef name uint N _t denotes an unsigned integer type with a width of N. Thus, uint24_t denotes an unsigned integer type with a width of exactly 24 bits.
ΒΆ3 These types are optional. However, if an implementation provides integer types with a width of 8, 16, 32, or 64 bits, it must specify the appropriate typedef names.
Jonathan leffler
source share