Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The difference of int8_t, int_least8_t and int_fast8_t?

Tags:

c

What is the difference between the int types int8_t, int_least8_t and int_fast8_t?

like image 459
NebulaFox Avatar asked Mar 10 '11 00:03

NebulaFox


People also ask

What does int8_t mean?

Thus, int8_t denotes a signed integer type with a width of exactly 8 bits.

What is int8_t and uint8_t?

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

What is int_fast16_t?

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.

What is int32_t in C?

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.


1 Answers

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".
like image 55
dan04 Avatar answered Sep 22 '22 11:09

dan04