RISC System/6000 Alignment Rules

On the RISC System/6000 system, an aggregate is aligned according to its most strictly aligned member. Within aggregates, members are aligned according to their type. The table below summarizes size and alignment information for each type.

Type, Size, and Alignment for the RISC System/6000 System
Type Alignment of Member Size (bytes)
char byte aligned 1
short halfword aligned 2
(long) int word aligned 4
long long int doubleword aligned 8
pointer word aligned 4
float word aligned 4
double doubleword aligned if -qalign=natural. Otherwise, word aligned. 8
long double
with -qlongdouble or -qldbl128 option.
long doubleword aligned if -qalign=natural. Otherwise, word aligned. 16

Notes:

  1. The entire object is aligned on the same boundary as its most strictly aligned member.
  2. Each member is assigned the lowest available offset with the appropriate alignment (internal padding).
  3. The object's size is increased, if necessary, to make it a multiple of the size of its most strictly aligned member. (For example, if the object contains a word, it is padded to a word boundary.)

On the RISC System/6000 system, if a double is the first member of a struct, it is 8-byte (doubleword) aligned. If a long double is the first member of a struct, it is 16-byte aligned.

Bit Fields for RISC System/6000 Format
The following rules apply when you are laying out bit fields in structs.

In the C language, you can specify bit fields as char or short instead of int, but the compiler maps them as if they were unsigned int. In extended mode, you can use the sizeof operator on a bit field. (The sizeof operator on a bit field always returns 4.)



align Compiler Option
Macintosh and Twobyte Alignment Rules
Packed Alignment Rules
Alignment Rules for Nested Aggregates