MacIntosh and Twobyte Alignment Rules

All unions and structures are halfword aligned regardless of their members. Within the aggregate, members are aligned according to their type. The size of types for the Macintosh system is the same as on the RISC System/6000 system. The table below summarizes alignment information for each type.

Type, Size, and Alignment for the Macintosh System
Type Alignment Size
char byte aligned byte
short halfword aligned halfword
(long) int halfword aligned word
long long int halfword aligned doubleword
pointer halfword aligned word
float halfword aligned word
double halfword aligned doubleword
long double halfword aligned doubleword
long double
with -qlongdouble
or -qldbl128 option.
halfword aligned quadrupleword

Example
The following example uses these symbols to show padding and boundaries:

     p = padding
     | = halfword boundary
     : = byte boundary

For:

     #pragma options align=mac68k
     struct A {
       char a;
     }
 
     sizeof(A) == 2

The layout of A is:

     |a:p|

For:

     #pragma options align=mac68k
     struct B {
       char a;
       double b;
     }
 
     sizeof(B) == 10

The layout of B is:

     |a:p|b:b|b:b|b:b|b:b|

Bit fields for Macintosh Format
The following rules apply when you are laying out bit fields in structures.

For unions, there is one special case:

Example
The following example uses these symbols to show padding and boundaries:

     p = padding
     | = halfword boundary
     : = byte boundary

For:

     #pragma options align=mac68k
     struct A {
       char a;
       int : 0;
       int b : 4;
       int c : 17;
     }
 
     sizeof(A) == 8

The layout of A is:

     |a:p|b .. :p|c:c|c .. :p|

Type Compatibility between RISC System/6000 and Macintosh Systems
Different aggregate types with identical members are not compatible. Therefore such aggregates cannot be assigned to each other. Use the -qextchk option to assure type safe linkage for function declarations that may use different alignment rules.



align Compiler Option
RISC System/6000 Alignment Rules
Packed Alignment Rules
Alignment Rules for Nested Aggregates