Basic data types—integer types
The compiler supports both all Standard C basic data types and some additional types.
Integer types—an overview
This table gives the size and range of each integer data type:
Data type | Size | Range | Alignment |
|---|---|---|---|
8 bits | 0 to 1 | 1 | |
8 bits | 0 to 255 | 1 | |
8 bits | -128 to 127 | 1 | |
8 bits | 0 to 255 | 1 | |
16 bits | -32768 to 32767 | 2 | |
16 bits | 0 to 65535 | 2 | |
32 bits | -231 to 231-1 | 4 | |
32 bits | 0 to 232-1 | 4 | |
| 32 bits 64 bits | -231 to 231-1 -263 to 263-1 | 4 |
| 32 bits 64 bits | 0 to 232-1 0 to 264-1 | 4 |
64 bits | -263 to 263-1 | 8 | |
64 bits | 0 to 264-1 | 8 |
Signed variables are represented using the two’s complement form.
Bool
The bool data type is supported by default in the C++ language. If you have enabled language extensions, the bool type can also be used in C source code if you include the file stdbool.h. This will also enable the boolean values false and true.
The enum type
The compiler will use the smallest type required to hold enum constants, preferring signed rather than unsigned.
When IAR language extensions are enabled, and in C++, the enum constants and types can also be of the type long, unsigned long, long long, or unsigned long long.
To make the compiler use a larger type than it would automatically use, define an enum constant with a large enough value. For example:
/* Disables usage of the char type for enum */ enum Cards{Spade1, Spade2, DontUseChar=257};
See also the C++ enum struct syntax.
For related information, see ‑‑enum_is_int.
The char type
The char type is by default unsigned in the compiler, but the ‑‑char_is_signed compiler option allows you to make it signed.
Note
The library is compiled with the char type as unsigned.
The wchar_t type
The wchar_t data type is 4 bytes and the encoding used for it is UTF-32.
The char16_t type
The char16_t data type is 2 bytes and the encoding used for it is UTF-16.
The char32_t type
The char32_t data type is 4 bytes and the encoding used for it is UTF-32.