pTAL Reference Manual (H06.08+)

Structures
HP pTAL Reference Manual523746-006
9-19
Alignment Considerations for Substructures
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.
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 substructure but might not be well-aligned with respect to the
base of the SHARED2 structure. Performance will be somewhat degraded when fields
in the substructure are referenced.
If a SHARED2 substructure is contained in a SHARED8 structure (or in an AUTO
structure), fields in the SHARED2 substructure will be well-aligned with respect to the
base of the SHARED2 substructure but might not be well-aligned with respect to the
base of the SHARED8 structure. Performance will be significantly degraded when
fields in the substructure are not well-aligned for SHARED8 access. Each such
reference will cause a trap to the millicode exception handler to resolve the reference.
Your program will behave correctly but will be significantly slower than it would without
the trap.
The compiler pads SHARED2 structures and substructures with an extra byte if the
end of the last field in the structure or substructure ends at an odd-byte address,
unless the structure has 1-byte alignmentthat is, all fields in the structure or
substructure are STRINGs or UNSIGNED(1-8).
STRING fields in structures can begin at any byte offset.
Table 9-4. Field Alignment of Substructures
Substructure
Field Alignment
Structure Field Alignment
AUTO PLATFORM SHARED8 SHARED2
AUTO AUTO PLATFORM Invalid Invalid
PLATFORM invalid PLATFORM invalid invalid
SHARED8 SHARED8 SHARED8 SHARED8 SHARED8
SHARED2 SHARED2 SHARED2 SHARED2 SHARED2
Default AUTO PLATFORM SHARED8 SHARED2
Example 9-11. AUTO Field Alignment in Structure (Error)
STRUCT s FIELDALIGN(SHARED8);
BEGIN
STRUCT s1 FIELDALIGN(AUTO); ! ERROR: Substructure cannot be
BEGIN ! FIELDALIGN(AUTO)
...
END;
END;