pTAL Conversion Guide

Structures
pTAL Conversion Guide527302-002
11-28
Structure Alignment
Structure Alignment
A structure’s alignment is the alignment of the widest field declared in the structure and
is always less than or equal to the alignment specified in a FIELDALIGN clause or
FIELDALIGN compiler directive. See Table 5-1 on page 5-2 for alignment values of
structure fields. The alignment of a field that is a substructure is the alignment of the
widest field contained in the substructure. For more information, see Substructure
Alignment on page 11-29.
If the alignment of the widest field in a SHARED8 structure is 2, the structure must
begin at a 2-byte address, and the structure’s base alignment is 2. If the alignment of
the widest field in the structure is four bytes, for example an INT(32), the structure
must begin at a four-byte address. If the alignment of the widest field in the structure is
eight bytes, for example an FIXED field, the structure must begin at an eight-byte
address.
In Example 11-11 on page 11-28,the specified field alignment for each structure is
SHARED8, but the base alignment is different in each structure because the alignment
of the widest field, c, is different in each.
Example 11-11. Structure Alignment
STRUCT s1 FIELDALIGN(SHARED8); ! Base alignment of structure
BEGIN ! is 2 because of INT c
STRING a; ! s1 begins at even-byte address
STRING b;
INT c; ! c is field with widest
END; ! alignment: 2
STRUCT s2 FIELDALIGN(SHARED8); ! Base alignment of structure
BEGIN ! is 4 because of INT(32) c
STRING a; ! s2 begins at 4-byte address
STRING b;
FILLER 2;
INT(32) c; ! c is field with widest
END; ! alignment: 4
STRUCT s3 FIELDALIGN(SHARED8); ! Base alignment of structure
BEGIN ! is 8 because of FIXED c
STRING a; ! s3 begins at 8-byte address
STRING b;
FILLER 6;
FIXED c; ! c is field with widest
END; ! alignment: 8