pTAL Reference Manual (H06.08+)

Structures
HP pTAL Reference Manual523746-006
9-16
Substructure Alignment
Substructure Alignment
The rules for field alignment of substructures are the same as the rules for structures.
You can specify the field alignment of a substructure explicitly using a FIELDALIGN
clause or implicitly by allowing the field alignment of the substructure to default to the
field alignment of the containing structure or substructure. In either case, the alignment
of fields must conform to the rules described previously, under Using Field Alignment.
For SHARED8 structures, you must ensure that every field begins at an appropriate
address and that the end of the structure includes filler, if necessary, so that the total
length of the substructure is an integral multiple of its widest field.
The following rules apply to substructures:
A definition substructure that does not specify a FIELDALIGN clause inherits the
field alignment of its containing structure or substructure.
The base alignment of a substructure is the alignment of the widest field of the
substructure.
Begin the base of a substructure at an offset that is an integral multiple of the
substructures alignment, relative to the start of its containing structure or
substructure. If the substructure is a definition substructure and both the structure
and substructure have SHARED8 field alignment, the substructure must be well
aligned.
For further information about substructures, see Alignment Considerations for
Substructures on page 9-19.
Example 9-6. Well-Aligned Structure With Well-Aligned Substructure
STRUCT s FIELDALIGN(SHARED8);
BEGIN
INT i;
FILLER 2; ! ss is 4-byte aligned. Use FILLER 2 to
! force ss to a 4-byte address
STRUCT ss; ! Specified alignment of ss is SHARED8,
BEGIN ! inherited from s
INT(32) m;
INT n;
FILLER 2; ! Alignment of substructure ss is 4
END; ! FILLER 2 makes total length of ss 8
INT j;
STRING t[0:2];
FILLER 3; ! Alignment of structure s is 4: declare
END; ! FILLER 3 to make length of s an integral
! multiple of its widest field