| |||
| Home > C and C++ Implementation Details > C and C++ implementation details > Basic data types | |||
This section describes how the basic data types are implemented in ARM C and C++.
Table 5.2 gives the size and natural alignment of the basic data types.
Table 5.2. Size and alignment of data types
| Type | Size in bits | Natural alignment in bytes |
|---|---|---|
| char | 8 | 1 (byte-aligned) |
| short | 16 | 2 (halfword-aligned) |
| int | 32 | 4 (word-aligned) |
| long | 32 | 4 (word-aligned) |
| long long | 64 | 8 (doubleword-aligned) |
| float | 32 | 4 (word-aligned) |
| double | 64 | 8 (doubleword-aligned) |
| long double | 64 | 8 (doubleword-aligned) |
| All pointers | 32 | 4 (word-aligned) |
| bool (C++ only) | 8 | 1 (byte-aligned) |
| _Bool (C only[a]) | 8 | 1 (byte-aligned) |
| wchar_t (C++ only) | 16 | 2 (halfword-aligned) |
[a] | ||
Type alignment varies according to the context:
Local variables are usually kept in registers, but when local variables spill onto the stack, they are always word-aligned. For example, a spilled local char variable has an alignment of 4.
The natural alignment of a packed type is 1.
See Structures, unions, enumerations, and bitfields for more information.
Integers are represented in two's complement form. The low word of a long long is at the low address in little-endian mode, and at the high address in big-endian mode.
Floating-point quantities are stored in IEEE format:
float values are represented by IEEE single-precision values
double and long double values are represented by IEEE double-precision values.
For double and long double quantities the word containing the sign, the exponent, and the most significant part of the mantissa is stored with the lower machine address in big-endian mode and at the higher address in little-endian mode. See Operations on floating-point types for more information.
The following statements apply to all pointers to objects in C and C++, except pointers to members:
Adjacent bytes have addresses that differ by one.
The macro NULL expands to the
value 0.
Casting between integers and pointers results in no change of representation.
The compiler warns of casts between pointers to functions and pointers to data.
The type size_t is defined as unsigned
int.
The type ptrdiff_t is defined
as signed int.