AVR data types¶
Traditional types¶
Traditional integer types (
deprecated):
- (signed/unsigned) char - 1 byte
- (signed/unsigned) short - 2 bytes
- (signed/unsigned) int - 2 bytes
- (signed/unsigned) long - 4 bytes
- (signed/unsigned) long long - 8 bytes
Floating point types:
- float - 4 bytes (floating point)
- double - alias to float
C99 types¶
C99 defines the following integer types:
- uint8_t/int8_t (1 byte, unsigned/signed)
- uint16_t/int16_t (2 byte)
- ...
When writing new code (or rewriting old code),
the C99 types should be prefered for the following reasons:
- Portability. When compiling the code for the PC (for use in the simulator), where the traditional types have a different size, programs might behave differently (especially if there are bugs due to variable overflow).
- Readability. It is immediately clear which variable size is used. Note that code is read more often than written, so even if it is more inconvenient to type, it is still an advantage.
- When writing the code, you have to make explicitly clear that you are using a 16 bit variable (instead of writing "int"), which introduce significant overhead on the AVR and should be avoided if possible.