pTAL Reference Manual (H06.03+)

Equivalenced Variables
HP pTAL Reference Manual523746-005
11-20
Structure Variants
Topics:
Structure Variants on page 11-20
Memory Usage for Structured Equivalenced Variables on page 11-21
FIELDALIGN Clause on page 11-22
Structure Variants
You use substructures to declare variant records in structures. pTAL does not detect
addresses that are redefined by equivalenced variant structures.
When you compile Example 11-9 on page 11-20, the compiler allocates 8 bytes, the
length of v1. Although v1 and v2 are different lengths and their fields have different
data types, the compiler does not report an error or a warning. You must ensure that
the variants are meaningful for your algorithms.
The structure in Example 11-10 on page 11-20 contains the same variants as the
structure in Example 11-9 on page 11-20, but the variants are in reverse order.
Example 11-9. Structure Variants
STRUCT s FIELDALIGN(AUTO);
BEGIN
STRUCT v1;
BEGIN
INT .p; ! .p is 4 bytes
INT q;
END;
STRUCT v2 = v1; ! v2 is equivalenced to v1
BEGIN ! v2 is 4 bytes
INT .EXT e;
END;
END;
Example 11-10. Structure Variants
STRUCT s FIELDALIGN(AUTO);
BEGIN
STRUCT v1;
BEGIN
INT .EXT e; ! e is 4 bytes
END;
STRUCT v2 FIELDALIGN(SHARED8) = v1;
BEGIN
INT .p; ! p is 4 bytes
INT q; ! Compiler reports a warning
END;
END;