pTAL Reference Manual (H06.08+)

Structures
HP pTAL Reference Manual523746-006
9-9
Base Alignment
Base Alignment
The base alignment of a structure is the alignment of the widest field in the structure.
The base alignment determines where the structure can be located in memory and be
well-aligned. A structure is well-aligned when the memory address at which it is located
is an integral multiple of its base alignment.
A structure is well-aligned if the address of the base of the structure in memory is a
multiple of its base alignment; otherwise, the structure is misaligned. If a structure is
misaligned, some or all of its fields will also be misaligned.
Structure Alignment Examples
The following examples illustrate how your structure data layout is affected by structure
alignment. Only SHARED8 structures are shown because SHARED2 structures are
not well-aligned. pTAL always generates conservative code for references to fields of a
SHARED2 structure that are more than 16 bits long.
Figure 9-1 on page 9-10 shows a structure, s1, that specifies
FIELDALIGN(SHARED8). Because the widest field in the structure, f, is a FIXED field,
the base alignment of s1 is 8. To be well-aligned, s1 must be allocated at a memory
address that is an integral multiple of eight. Filler is added as follows:
Before i32 so that i32 begins at an offset that is a multiple of four relative to the
beginning of the structure.
Before f so that f begins at an offset that is a multiple of eight relative to the
beginning of the structure.
At the end of the structure so that the total length of the structure is an integral
multiple of the widest field in the structure.
Table 9-3. Base Alignment and Field Alignment Relationships
Width of Widest Field in Structure FIELDALIGN(SHARED2) FIELDALIGN(SHARED8)
1 1 or 2* 1 or 2*
222
424
828
*Definition (inline) substructures have a base alignment of one. All other structuresdefinition structures,
referral structures, and referral substructureshave a base alignment of two.