pTAL Reference Manual (H06.08+)

Structures
HP pTAL Reference Manual523746-006
9-18
Substructure Alignment
When you design routines that return addresses to their callers, return addresses that
are well-aligned whenever possible.
The compiler always generates conservative code. In Example 9-9 on page 9-18,
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 p4for
example, p4.jdo not cause traps because the field alignment of s4 is SHARED2
and the compiler generates conservative code for such references.
Example 9-9. 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
Example 9-10. 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