pTAL Reference Manual (G06.24+, H06.09+, J06.03+)

Example 60 SHARED8 Structure With SHARED2 Substructure
STRUCT s3 FIELDALIGN(SHARED8);
BEGIN ! Base alignment of s3 is 4
INT i;
STRUCT s4(t_s2); ! s2 has SHARED8 alignment
END; ! Base alignment of s2 is 4
INT .p4(t_s2); ! Uses default alignment: 2
The compiler always generates conservative code. In Example 60 (page 126), references to s3.s4.j
do not cause traps because, although s3 is SHARED8, the offset of s3.s4.j is not a multiple of
4. For each reference pTAL determines whether the referenced field is well-aligned. References to
fields in s4 using the pointer p4—for example, p4.j—do not cause traps because the field
alignment of s4 is SHARED2 and the compiler generates conservative code for such references.
Example 61 Combining SHARED2 and SHARED8 Structures
PROC p;
BEGIN
STRUCT s1 FIELDALIGN(SHARED8); ! OK
BEGIN
FIXED i;
END;
STRUCT s2 FIELDALIGN(SHARED2); ! OK
BEGIN
INT(32) i; ! OK
STRUCT sub (s1); ! WARNING: SHARED8
END; ! substructure in SHARED2
! structure can cause
! significant loss of
! performance
STRUCT s3 (s1) = s2;
STRUCT s4 FIELDALIGN(SHARED8);
BEGIN
INT i;
STRUCT sub1 (s2); ! OK: SHARED2
STRUCT sub2 (s1) = sub1; ! WARNING: SHARED8 substructure
FILLER 2; ! redefines SHARED2 substructure
END; ! can cause significant loss of
END; ! performance
Alignment Considerations for Substructures
When you declare a substructure, you must be aware of how the base alignment of the substructure
and its containing structure affect references to the fields of the structure and substructure.
Table 44 Field Alignment of Substructures
Structure Field Alignment
SHARED2SHARED8PLATFORMAUTOSubstructure Field
Alignment
InvalidInvalidPLATFORMAUTOAUTO
invalidinvalidPLATFORMinvalidPLATFORM
SHARED8SHARED8SHARED8SHARED8SHARED8
SHARED2SHARED2SHARED2SHARED2SHARED2
SHARED2SHARED8PLATFORMAUTODefault
If a SHARED8 substructure is contained in a SHARED2 structure (or in an AUTO structure), fields
in the SHARED8 substructure will be well-aligned with respect to the base of the SHARED8
126 Structures