What is the difference between the int types int8_t
, int_least8_t
and int_fast8_t
?
Thus, int8_t denotes a signed integer type with a width of exactly 8 bits.
uint8_t and int8_t are optional integer types of exactly 8 bits. Both types have no padding, and int8_t uses 2's complement. uint8_t is unsigned, and has the range zero to UINT8_MAX , which is [0, +255]. int8_t is signed, and has the range INT8_MIN to INT8_MAX , which is [−128, +127].
int_fast16_t is most efficient type in speed with at least the range of a 16 bit int. Example: A given platform may have decided that int should be 32-bit for many reasons, not only speed. The same system may find a different type is fastest for 16-bit integers.
That's where int32_t comes in: it's an alias for whatever integer type your particular system has that is exactly 32 bits. Template: intN_t or uintN_t Where N is width of integer which can be 8, 16, 32, 64 or any other type width supported by the library.
The difference is defined in the sections of the C99 standard that Carl Norum quoted. But it may be useful to have an example.
Suppose you have a C compiler for a 36-bit system, with char
= 9 bits, short
= 18 bits, int
= 36 bits, and long
= 72 bits. Then
int8_t
does not exist, because there is no way to satisfy the constraint of having exactly 8 value bits with no padding.int_least8_t
is a typedef of char
. NOT of short
or int
, because the standard requires the smallest type with at least 8 bits.int_fast8_t
can be anything. It's likely to be a typedef of int
if the "native" size is considered to be "fast".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