pTAL Conversion Guide

Structures
pTAL Conversion Guide527302-002
11-29
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.
Rules for substructures:
A definition substructure that does not specify a field align 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.
The base of a substructure must begin at an offset that is an integral multiple of the
substructure’s 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.
See Alignment Considerations for Structures and Substructures on page 11-34 for
further considerations about using substructures.
Example 11-12. Well-Aligned Substructure of Well-Aligned Structure
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
END; ! Declare FILLER 3 to make length of s an
! integral multiple of its widest field