pTAL Guidelines for TAL Programmers

Coding Guidelines
pTAL Guidelines for TAL Programmers527256-002
2-7
Referencing Variables and Parameters
Example 2-2 on page 2-6 does not work in a pTAL program running as a native
process because native compilers optimize the time required to access variables and
parameters by:
Arranging the items in memory for optimal access (the actual order of the variables
in memory might differ from the order in which you declare them)
Inserting filler between items
To ensure the position of one variable relative to another in pTAL, use elements of an
array, fields of a structure, or an equivalenced declaration.
Example 2-3 on page 2-7 has a buffer in which it scans messages. A STRING variable
with the value zero immediately follows the buffer and ensures that the scan stops.
Example 2-3 on page 2-7 might not work in pTAL because the native compiler might
not allocate space for stopper immediately after the array scan_buff. Two ways to
achieve the same effect in pTAL are:
Make scan_buff one byte longer and store zero in its last element, as in
Example 2-4 on page 2-7.
Declare scan_buff and stopper as fields of a structure, as in Example 2-5 on
page 2-8. pTAL allocates the fields of a structure in the order in which you declare
them.
Example 2-4 on page 2-7 and Example 2-5 on page 2-8 work in both TAL and pTAL.
Example 2-3. Zero in Variable After Buffer Ensures That Scan Stops (TAL Only)
STRING scan_buff [0:79]; ! Buffer for scanning stopper
STRING stopper := 0; ! immediately follows buffer
SCAN scan_buff WHILE " "; ! If line is blank,
! zero in stopper stops scan
Example 2-4. Zero in Last Element of Buffer Ensures That Scan Stops
STRING scan_buff[0:80]; ! Buffer for scanning
scan_buff[80] := 0; ! Last element of buffer is zero
SCAN scan_buff WHILE " "; ! If line is blank,
! zero in scan_buff[80] stops scan