The C99 standard introduces the following datatypes. The documentation can be found here for the AVR stdint library.
uint8_t
means it's an 8-bit unsigned type.uint_fast8_t
means it's the fastest unsigned int with at least 8 bits.uint_least8_t
means it's an unsigned int with at least 8 bits.I understand uint8_t
and what is uint_fast8_t
( I don't know how it's implemented in register level).
1.Can you explain what is the meaning of "it's an unsigned int
with at least 8 bits"?
2.How uint_fast8_t
and uint_least8_t
help increase efficiency/code space compared to the uint8_t
?
The difference between Uint8 and uint8_t will depend on implementation, but usually they will both be 8 bit unsigned integers. Also uint8_t and uint16_t are defined by C (and maybe C++) standard in stdint. h header, Uint8 and Uint16 are non-standard as far as I know.
If the intended use of the variable is to hold an unsigned numerical value, use uint8_t; If the intended use of the variable is to hold a signed numerical value, use int8_t; If the intended use of the variable is to hold a printable character, use char.
Unsigned Integers of 8 bits. A uint8 data type contains all whole numbers from 0 to 255. As with all unsigned numbers, the values must be non-negative. Uint8's are mostly used in graphics (colors are always non-negative).
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].
uint_least8_t
is the smallest type that has at least 8 bits. uint_fast8_t
is the fastest type that has at least 8 bits.
You can see the differences by imagining exotic architectures. Imagine a 20-bit architecture. Its unsigned int
has 20 bits (one register), and its unsigned char
has 10 bits. So sizeof(int) == 2
, but using char
types requires extra instructions to cut the registers in half. Then:
uint8_t
: is undefined (no 8 bit type).uint_least8_t
: is unsigned char
, the smallest type that is at least 8 bits.uint_fast8_t
: is unsigned int
, because in my imaginary architecture, a half-register variable is slower than a full-register one.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