pTAL Conversion Guide

Pointers
pTAL Conversion Guide527302-002
10-24
Pointer Arithmetic
Pointer Arithmetic
TAL
All addresses are INT or INT(32) values, which you can use as operands in
expressions anywhere an INT or INT(32) value is valid. For example, the following
code rounds an address up to the next address that is an integral multiple of 32 if the
address is not already an integral multiple of 32:
INT .x; ! Declare a pointer
@x := (@x '+' 3) / 4 * 4; ! Round @x up to next 4-byte address
pTAL
The preceding assignment statement is invalid in pTAL because the data type of @x is
WADDR. Although you can add or subtract a constant value to a WADDR—3 in the
preceding statement—you cannot perform division or multiplication on a WADDR.
In pTAL, arithmetic on addresses is restricted to the operations shown in Table 10-8 on
page 10-25.
Example 10-7. Address Shifts (pTAL)
Invalid:
INT a;
STRING .b;
INT(32) .SG c;
STRING .SGX d;
@c := @b '>>' 1; ! ERROR: Cannot convert BADDR to SGWADDR
Valid:
INT a;
STRING .b;
INT(32) .SG c;
STRING .SGX d;
@b := @a '<<' 1; ! Convert WADDR to BADDR
@c := @d '>>' 1; ! Convert SGXBADDR to SGWADDR