pTAL Reference Manual (H06.08+)

Equivalenced Variables
HP pTAL Reference Manual523746-006
11-21
Memory Usage for Structured Equivalenced
Variables
In Example 11-10 on page 11-20, v1 is 4 bytes, but v2 is 8 bytes. The compiler reports
a warning. Data that your program stores into s.v2.q overwrites the data in the
memory locations that follow s.
v2 is 8 bytes to maintain the alignment of variables in memory. For more information
about lengths of pTAL structures, see Section 9, Structures.
Memory Usage for Structured Equivalenced Variables
The memory referenced in an equivalenced declaration must fit within the memory
allocated for the previous variable. When you determine the length of a structure, you
must account for filler that pTAL adds to the structure. In Example 11-11 on
page 11-21, the equivalenced declaration is not valid because b is 4 bytes, but a is
only 3 bytes. pTAL adds an extra byte at the end of b so that its total length is an
integral multiple of its longest component, i.
If you declare b and then declare a, pTAL does not report an error because a fits within
the four bytes already allocated for b, as in Example 11-12 on page 11-21.
Example 11-11. Memory Usage for Structured Equivalenced Variables (Incorrect)
STRUCT a FIELDALIGN(SHARED2); ! Structure a is 3 bytes
BEGIN
STRING i;
STRING j;
STRING k;
END;
STRUCT b FIELDALIGN(AUTO) = a; ! Structure b is 4 bytes
BEGIN
INT i;
STRING j; ! pTAL adds a byte after field j
END;
Example 11-12. Memory Usage for Structured Equivalenced Variables (Correct)
STRUCT b FIELDALIGN(AUTO);
BEGIN
INT i;
STRING j; ! pTAL adds a byte after the declaration of j
END;
STRUCT a FIELDALIGN(SHARED2) = b;
BEGIN
STRING i;
STRING j;
STRING k;
END;