| |||
| Home > ARM Compiler Reference > C and C++ implementation details > Basic data types | |||
This section provides information about how the basic data types are implemented in ARM C and C++.
Table 3.3 gives the size and natural alignment of the basic data types. Note that type alignment varies, depending on the context in which the type is used:
The alignment of top level
static objects such as global variables is the maximum of the natural
alignment for the type and the value set by the -zat compiler
option. For example, if -zat2 is specified, a global char variable
has an alignment of 2. This option is described in Setting alignment options.
Local variables are always word aligned. For example, a local char variable has an alignment of 4.
The natural alignment of a packed type is 1.
Table 3.3. Size and alignment of data types
| Type | Size in bits | Natural alignment |
|---|---|---|
| char | 8 | 1 (byte aligned) |
| short | 16 | 2 (halfword aligned) |
| int | 32 | 4 (word aligned) |
| long | 32 | 4 (word aligned) |
| long long | 64 | 4 (word aligned) |
| float | 32 | 4 (word aligned) |
| double | 64 | 4 (word aligned) |
| long double | 64 | 4 (word aligned) |
| all pointers | 32 | 4 (word aligned) |
| bool[1] | 32 | 4 (word aligned) |
[1] Applies to C++ only. | ||
The following points apply to the char data type:
Data items of type char are unsigned by default. In C++ mode and ANSI C mode they may be explicitly declared as signed char or unsigned char.
In PCC mode there is no signed keyword. Therefore a char is signed by default and may be declared unsigned if required.
Integers are represented in two's complement form. The high word of long long integers is always at the highest address. Refer to Operations on integral types for more information.
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. In double and long double quantities, the word containing the sign, the exponent, and the most significant part of the mantissa is stored at the lower machine address. Refer to Operations on floating-point types for more information.
The following remarks apply to all pointer types in C, and to all pointer types except pointers to members in C++:
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, except when PCC mode is specified.
The type size_t is defined as unsigned
int, except in PCC mode where it is signed.
The type ptrdiff_t is defined
as signed int.
Refer to Pointer subtraction for more information.