pTAL Guidelines for TAL Programmers
Coding Guidelines
pTAL Guidelines for TAL Programmers—527256-002
2-23
Equivalenced Variables and Indirect Pointers
Equivalenced Variables and Indirect Pointers
Guideline: Do not equivalence an integer to the implicit pointer of an indirect array or
indirect structure.
In TAL, you can equivalence a variable to the implicit pointer of an indirect array or
indirect structure. In Example 2-21
on page 2-23, if you store an address into p, you
are actually storing the address into the implicit pointer to a’s data. In so doing, you
change the implicit pointer such that it no longer points to the array or structure that
you declared.
In pTAL, you cannot equivalence a variable to the implicit pointer of an indirect array or
indirect structure, regardless of whether the variable, the indirect array, or the indirect
structure is in the user data segment or in an extended data segment. Similarly, you
cannot equivalence an indirect array or indirect structure to a variable; therefore, the
equivalenced declaration in Example 2-21
on page 2-23 is not valid in pTAL.
Example 2-20. Scanning Algorithm
DEFINE found = 1#;
INT PROC scan_until(ptr:cnt, search_char);
STRING .EXT ptr;
INT cnt;
STRING .search_char;
BEGIN
STRING .EXT loc;
STRING last_char := ptr[cnt - 1];
ptr[cnt - 1] := search_char; ! Ensure that scan stops
@loc := @ptr; ! Initialize to first
! character in string
WHILE loc <> search_char DO ! Scan for search_char
@loc := @loc[1]; ! Didn't find so index
! to next
IF @loc <> @ptr[cnt - 1] THEN ! If stopped before end,
BEGIN ! restore last character
ptr[cnt - 1] := last_char;
RETURN found;
END;
IF last_char = search_char THEN ! Last character is
RETURN found; ! already correct
RETURN NOT found;
END;
Example 2-21. Equivalencing a Variable to an Indirect Pointer (TAL Only)
INT .a[0:99]; ! Declare indirect array a
INT p = a; ! Equivalence p to the implicit pointer of a