pTAL Conversion Guide

Pointers
pTAL Conversion Guide527302-002
10-26
Pointer Arithmetic
Topics:
Stepping Pointers Using Indexing (pTAL) on page 10-26
Stepping Pointers Using Arithmetic (pTAL) on page 10-27
Computing the Number of Bytes Between Addresses (pTAL) on page 10-29
Comparing Addresses to Addresses (pTAL) on page 10-31
Comparing Addresses to Constants (pTAL) on page 10-31
Comparing PROCADDRs to PROCPTRs (pTAL) on page 10-32
Abbreviated Comparisons on page 10-32
Example Revisited on page 10-33
Stepping Pointers Using Indexing (pTAL)
You can increment or decrement the value of a pointer using either indexing (described
in this topic) or explicit addition and subtraction operations on addresses (see Stepping
Pointers Using Arithmetic (pTAL) on page 10-27).
The first group of expressions in Table 10-8 on page 10-25 uses indexing to access an
array element. Indexing produces the correct result for all data types including
structures. Use indexing wherever possible to adjust pointers.
procaddr relational procaddr int PROCADDR pa;
procptr relational procaddr int PROCPTR p;END PROCPTR;
IF @p '=' pa THEN...;
Example 10-8. Stepping Pointers Using Indexing (pTAL) (page 1 of 2)
INT .a[0:99]; ! 100-word array
STRING .b[0:9]; ! 10-byte array
STRUCT .s[0:9]; ! 10-element array
BEGIN
...
END;
Table 10-8. Valid Address Expressions (page 2 of 2)
Template
1
Result Type Example
1. atype is any data type except PROCADDR and EXTADDR.
2. The result of subtracting two address types is the number of bytes between them for byte-oriented address
types (BADDR, CBADDR, SGBADDR, SGXBADDR, EXTADDR) and is the number of 16-bit words between
them for word-oriented data types (WADDR, CWADDR, SGWADDR, SGXWADDR).
3. relational must be an unsigned relational operator ('<', '=', '>', '<=', '<>', '>=') or signed equal or not equal
(=, <>).
4. relational must be a signed relational operator (<, =, >, <=, <>, >=).