pTAL Guidelines for TAL Programmers
Coding Guidelines
pTAL Guidelines for TAL Programmers—527256-002
2-20
Addresses Are Indivisible
In general, compare addresses only to zero or to a value that you use to represent a nil
value. Do not depend on constant memory addresses.
Addresses Are Indivisible
Guideline: Treat addresses as indivisible entities.
Do not attempt to change or create addresses programmatically based on knowledge
of address fields that represent a page, a segment, an offset, or any other address
component. In TAL, some programs create an extended address, for example to
reference string data in the upper half of the user data segment. This technique does
not work in native processes.
Addresses Are Absolute
Guideline: Do not make program behavior depend on the absolute location of data in
memory as determined by the values of addresses.
Do not make program behavior depend on the absolute location of data in memory as
determined by the values of addresses. Use memory addresses only to compute
lengths of buffers or to compare addresses to each other.
Example 2-16
on page 2-20 and Example 2-17 on page 2-21 are valid in pTAL and
TAL.
Example 2-15. Comparing Addresses to Constants
INT .i;
STRING .s;
INT .EXT e;
STRING .SG sgb;
IF @i '>' 0 THEN...; ! @i is WADDR, needs unsigned comparison
IF @s <> 0 THEN...; ! @s is BADDR, signed <> (and =) OK
IF @e = 0d THEN...; ! @e is EXTADDR, needs signed =
IF @sgb = 0 THEN...; ! @sgb is SGBADDR, signed = OK
Example 2-16. Using Addresses to Find String Length
STRING .a[0:90];
STRING .ptr;
INT len;
SCAN a until " " -> @ptr;
len := @ptr '-' @a;