Legacy Documentclose button

Important: The information in this document is obsolete and should not be used for new development.

Previous Book Contents Book Index Next

Inside Macintosh: Mac OS Runtime Architectures /
Chapter 4 - PowerPC Runtime Conventions


Data Alignment

The PowerPC runtime environment supports multiple data alignment modes. These alignments fall into two categories:

For example, the alignment of a UInt16 variable may differ from that of a UInt16 data item embedded in a data structure.

Note
Data items passed as parameters in a routine call have their own special alignment rules. See "Routine Calling Conventions," beginning on page 4-11, for more information.
Table 4-1 (page 4-3) shows the natural alignment of each data type, which is simply the size of the data type. This alignment is fixed.

In data structures, you can specify an embedding alignment that varies depending on the alignment mode selected. Typically you can select the alignment mode using compiler options or pragmas. Table 4-2 shows the possible alignment modes.
Table 4-2 Embedded alignment modes
Data typePowerPC68KPackedNatural
SInt8

UInt8

Boolean

1111
SInt16

UInt16

2212
SInt32

UInt32

4214
float4214
double4 or 8218
Pointer4214
Composite4 or 82116

In all but the 68K alignment mode, the embedding alignment of a composite (for example, a data structure or an array) is determined by the largest embedding alignment of its members. The total size of a composite is rounded up to be a multiple of its embedded alignment.

In 68K alignment mode, the embedded alignment of a composite is always 2 bytes. The total size of the composite is rounded up to a multiple of two.

In PowerPC alignment mode, if the first embedded element in a data structure is type double, then the embedding alignment of all type double members in the structure is 8. In such cases, the embedding alignment for the entire structure is also 8 bytes.

Note that you may need to adjust embedded alignments if you are converting code from the classic 68K environment to the PowerPC (or CFM-68K) runtime environments. If you wish to enforce classic 68K alignment on your PowerPC code, you can often specify compiler pragmas or options to do so. Note, however, that the PowerPC processor is less efficient when accessing data that is not placed according to its natural alignment.


Previous Book Contents Book Index Next

© Apple Computer, Inc.
11 MARCH 1997