pTAL Guidelines for TAL Programmers

Coding Guidelines
pTAL Guidelines for TAL Programmers527256-002
2-22
Addresses Are Absolute
Example 2-18 on page 2-21 has two statements that are not valid in a pTAL program
that runs as a native process:
The IF statement compares the address in the pointer xptr to %2000000d. The
comparison assumes that addresses that are less than %2000000d are in the user
data segment, and that addresses equal to or greater than %2000000d are in an
extended data segment. In a pTAL program running as a native process, the
values of addresses are not predictable and can change from one RVU to another;
therefore, the preceding assumption is not valid in a pTAL program that runs as a
native process.
The assignment statement @LOC := $INT(@XPTR) assumes that you can convert
an extended address whose value is less than %2000000d to an address in the
user data segment by using only the rightmost 16 bits of the 32-bit address. This
assumption is not valid in a pTAL program running as a native process. Also, the
data type of @LOC is BADDR, whereas the data type of the value returned by $INT
is INT. pTAL does not permit you to assign a nonconstant value of type INT to a
pointer or variable of type BADDR.
To make Example 2-18 on page 2-21 compatible with pTAL, either:
Remove the test and always move the data to a local buffer, even if it is already in
the user data segment, as in Example 2-19 on page 2-22.
Code your own scanning algorithm, as in Example 2-20 on page 2-23.
Example 2-19. Ensuring Location of Data Before Scanning
PROC p(xptr:cnt);
STRING .EXT xptr;
INT cnt;
BEGIN
STRING .loc;
STRING .buff[0:99];
IF cnt > 99 THEN CALL error(...);
buff[99] := 0; ! Ensure that scan stops
buff ':='xptr FOR cnt BYTES; ! Move data to user data segment
SCAN buff UNTIL " " -> @loc; ! Scan data
END;