Keil™, An ARM® Company

CARM User's Guide

Discontinued

Byte Alignment

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 4-byte variables using one instruction only when the object is stored at an address divisible by four. So, 4-byte objects are located on 4-byte boundaries.

By default, the CARM Compiler stores data objects as follows:

TypeBytesAlignment
char1Located at any byte address.
short2Located at an address evenly divisible by 2.
float,
int,
long,
pointer
4Located at an address evenly divisible by 4.
long long,
double
8Located at an address evenly divisible by 4.

Note

  • Alignment is relevant when the compiler locates variables to physical memory addresses. For instance, in the following struct:
    struct example_st
      {
      int  amem;
      char bmem;
      int  cmem;
      };
    

    a 3-byte gap is required between bmem and cmem.