pTAL Conversion Guide

Equivalenced Variables
pTAL Conversion Guide527302-002
12-15
Using Structure Variants
Using Structure Variants
In TAL and pTAL, you use substructures to declare variant records in structures. pTAL
does not detect addresses that are redefined by equivalenced variant substructures.
When you run the code in Example 12-12 on page 12-15 as a native process, v1 is
eight bytes (p is four bytes, q is two bytes, and the native compiler adds two bytes at
the end of substructure v1). v2 is four bytes. The native compiler allocates eight bytes,
the length of v1. Although v1 and v2 are different lengths and their fields have
different data types, the native compiler does not report an error or a warning. You
must ensure that the variants are meaningful for your algorithms.
The structure in Example 12-13 on page 12-16 contains the same variants as the
structure in Example 12-12 on page 12-15, but the variants are in reverse order. v1
and v2 are each four bytes on TNS architecture. On native architecture, v1 is four
bytes, but v2 is eight bytes. The native compiler reports a warning for this case. Data
that your program stores into s.v2.q as a native process overwrites the data in the
memory locations that follow s.
PROCPTR f; ! f is a procedure pointer equivalenced
END PROCPTR = b; ! to a procedure address
Example 12-12. Structure Variants
STRUCT s FIELDALIGN(AUTO);
BEGIN
STRUCT v1;
BEGIN
INT .p; ! .p is 2 bytes on TNS architecture,
INT q; ! 4 bytes on native architecture
END;
STRUCT v2 = v1; ! v2 is equivalenced to v1
BEGIN
INT .EXT e; ! v2 is 4 bytes on
END; ! TNS & native architectures
END;
Example 12-11. Equivalencing PROCADDRs and PROCPTRs (page2of2)