All structures are byte-aligned regardless of their members. All members are also byte-aligned. (Bit fields are byte-aligned, but bit-field members are not.)
Example
The following example uses these symbols to show padding and
boundaries:
p = padding | = halfword boundary : = byte boundary
For:
#pragma options align=packed struct { char a; double b; } B; #pragma options align=reset sizeof(B) == 9
The layout of B is:
|a:b|b:b|b:b|b:
Packed Bit Fields
The following rules apply when laying out packed bit fields.
Example
#pragma options align=packed
struct {
char a;
int b : 10;
int c : 12;
int d : 4;
int e : 3;
int : 0;
int f : 1;
char g;
} A;
#pragma options align=reset
sizeof(A) == 7
The layout of A is:
Member Name Displacement
bytes (bits)a 0 b 1 c 2 (2) d 4 e 4 (4) f 5 g 6
align Compiler Option
RISC System/6000 Alignment Rules
Macintosh and Twobyte Alignment Rules
Alignment Rules for Nested Aggregates