pTAL Reference Manual (H06.03+)

Equivalenced Variables
HP pTAL Reference Manual523746-005
11-4
Memory Allocation
Memory Allocation
pTAL does not allocate memory for equivalenced variables. In the following example,
pTAL allocates memory only for base_previous:
INT base_previous;
INT equivalenced1 = base_previous;
INT equivalenced2 = equivalenced1;
An equivalenced variable is an alias for memory allocated for a previously declared
variable. The equivalenced declaration can specify different attributes; for example, a
different data type than those of the previous variable. In the following example, pTAL
allocates 32 bits for i. The equivalenced declaration for j references the memory
allocated for i, but specifies that the bits be treated as a REAL number:
INT(32) i;
REAL j = i;
If an equivalenced variable is a standard or extended pointer and the previous variable
is the implicit pointer of an indirect array or indirect structure, the equivalenced variable
is a read-only pointer. You can use the value of the pointer in an expression, but you
cannot store an address or other value into the pointer because doing so would be the
same as storing an address into the implicit pointer of the array or structure. You can,
however, use a pointer to read or write the data to which the pointer points.
Example 11-2. Equivalenced Pointers
INT .a[0:3];
INT .p = a;
WADDR w;
PROC p1;
BEGIN
a[1] := a[1] + 1; ! Increment second word of a
p[1] := p[1] + 1; ! Increment second word of p (= a)
w := @a; ! Assign address of first word of a to w
w := @p; ! Assign address of first word of p (= a)
! to w
END;
PROC p2;
BEGIN
@p := w; ! ERROR: Cannot assign to an equivalenced pointer
! when it is equivalenced to an indirect or
! standard indirect variable
END;