5.5. Aligning data

The various C data types are aligned on specific byte boundaries to maximize storage potential and to provide for fast, efficient memory access with the ARM instruction set. For example, the ARM architecture can access a four-byte variable using only one instruction when the object is stored at an address divisible by four, so four-byte objects are located on four-byte boundaries.

By default, the compiler stores data objects as shown in Table 5.9.

Table 5.9. Compiler storage of data objects by byte alignment

TypeBytesAlignment
char1Located at any byte address.
short2Located at any address that is evenly divisible by 2.
float, int, long, pointer4Located at an address that is evenly divisible by 4.
long long double8Located at an address that is evenly divisible by 4.

Data alignment becomes relevant when the compiler locates variables to physical memory addresses. For example, in the following structure, a three-byte gap is required between bmem and cmem.

struct example_st {
  int amem;
  char bmem;
  int cmem;
};

ARM and Thumb processors are designed to efficiently access naturally-aligned data, that is, doublewords that lie on addresses that are multiples of four, words that lie on addresses that are multiples of four, halfwords that lie on addresses that are multiples of two, and single bytes that lie at any byte address. Such data is located on its natural size boundary.

Copyright © 2002-2010 ARM. All rights reserved.ARM DUI 0205J
Non-ConfidentialID101213