3.2.2. Basic data types

This section provides information about how the basic data types are implemented in ARM C and C++.

Size and alignment of basic data types

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

TypeSize in bitsNatural alignment
char81 (byte aligned)
short162 (halfword aligned)
int324 (word aligned)
long324 (word aligned)
long long644 (word aligned)
float324 (word aligned)
double644 (word aligned)
long double644 (word aligned)
all pointers324 (word aligned)
bool[1]324 (word aligned)

[1] Applies to C++ only.

Char

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.

Integer

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.

Float

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.

Pointers

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.

Copyright © 1997, 1998 ARM Limited. All rights reserved.ARM DUI 0041C