pTAL Conversion Guide

Pointers
pTAL Conversion Guide527302-002
10-30
Pointer Arithmetic
Rules for subtracting one address from another:
Neither address can be a PROCADDR address.
The addresses must be the same type except that:
°
SGBADDR and SGXBADDR are interchangeable.
°
SGWADDR and SGXWADDR are interchangeable.
The result of subtracting two addresses depends on their type:
Address Type Result
INT INT
EXTADDR INT(32)
Byte-oriented
(BADDR,
CBADDR,
SGBADDR,
SGXBADDR,
EXTADDR)
Number of bytes between the addresses
Word-oriented
(WADDR,
CWADDR,
SGWADDR,
SGXWADDR)
Number of 16-bit words between the addresses
Example 10-11. Subtracting One Address From Another (pTAL)
Invalid:
INT(32) i32;
STRING str1;
BADDR b;
INT .EXT i;
STRING .EXT str2;
i := @str1 - b; ! ERROR: unsigned arithmetic required
i := @str1 '-' @b; ! ERROR: BADDR '-' WADDR is invalid
Valid:
INT(32) i32;
STRING str1;
BADDR b;
INT .EXT i;
STRING .EXT str2;
i := b '-' @str1; ! Both operands are BADDRs
i32 := @i - @str2; ! Both operands are EXTADDRs