Table 5-1 lists the size, representation, and range of each scalar data type for the MSP430 compiler. Many of the range values are available as standard macros in the header file limits.h.
The storage and alignment of data types is described in Section 6.2.
Range | |||||
---|---|---|---|---|---|
Type | Size | Alignment | Representation | Minimum | Maximum |
signed char | 8 bits | 8 | Binary | -128 | 127 |
char | 8 bits | 8 | ASCII | 0 or -128 (1) | 255 or 127 (1) |
unsigned char | 8 bits | 8 | Binary | 0 | 255 |
bool (C99) | 8 bits | 8 | Binary | 0 (false) | 1 (true) |
_Bool (C99) | 8 bits | 8 | Binary | 0 (false) | 1 (true) |
bool (C++) | 8 bits | 8 | Binary | 0 (false) | 1 (true) |
short, signed short | 16 bits | 16 | Binary | -32 768 | 32 767 |
unsigned short | 16 bits | 16 | Binary | 0 | 65 535 |
int, signed int | 16 bits | 16 | Binary | -32 768 | 32 767 |
unsigned int | 16 bits | 16 | Binary | 0 | 65 535 |
long, signed long | 32 bits | 16 | Binary | -2 147 483 648 | 2 147 483 647 |
unsigned long | 32 bits | 16 | Binary | 0 | 4 294 967 295 |
long long, signed long long | 64 bits | 16 | Binary | -9 223 372 036 854 775 808 | 9 223 372 036 854 775 807 |
unsigned long long | 64 bits | 16 | Binary | 0 | 18 446 744 073 709 551 615 |
enum | varies (2) | 16 | Binary | varies | varies |
float | 32 bits | 16 | IEEE 32-bit | 1.175 494e-38(3) | 3.40 282 346e+38 |
double | 64 bits | 16 | IEEE 64-bit | 2.22 507 385e-308(3) | 1.79 769 313e+308 |
long double | 64 bits | 16 | IEEE 64-bit | 2.22 507 385e-308(3) | 1.79 769 313e+308 |
function and data pointers | varies (see Table 5-2) | 16 |
The char type is unsigned by default. This is in contrast to the "signed char" and "unsigned char" types, which specify their sign behavior. You can change the default for the "char" type using the --plain_char=signed compiler option.
Negative values for signed types are represented using two's complement.
The additional types from C, C99 and C++ are defined as synonyms for standard types:
typedef unsigned int wchar_t;
typedef unsigned int wint_t;
MSP devices support multiple data and code memory models. The code and data model affects the size, alignment, and storage space used for function pointers, data pointers, the size_t type, and the ptrdiff_t type. Pointers with sizes that are not a power of 2 are always stored in a container with a size of a power of 2 bits. That is, 20-bit types are stored in 32 bits.
Code or Data Model | Type | Size | Storage | Alignment |
---|---|---|---|---|
small code model | function pointer | 16 | 16 | 16 |
large code model | function pointer | 20 | 32 | 16 |
small data model | data pointer | 16 | 16 | 16 |
small data model | size_t | 16 | 16 | 16 |
small data model | ptrdiff_t | 16 | 16 | 16 |
restricted data model | data pointer | 20 | 32 | 16 |
restricted data model | size_t | 16 | 16 | 16 |
restricted data model | ptrdiff_t | 16 | 16 | 16 |
large data model (1) | data pointer | 20 | 32 | 16 |
large data model | size_t | 32 | 32 | 16 |
large data model | ptrdiff_t | 32 | 32 | 16 |