pTAL Conversion Guide

Statements
pTAL Conversion Guide527302-002
15-4
Data Types Must Match
pTAL
pTAL disallows assignments of unlike data types, with these exceptions:
STRING and UNSIGNED(1-15) variables are valid anywhere INT variables are
valid.
UNSIGNED(17-31) variables are valid anywhere INT(32) variables are valid.
An UNSIGNED(1-15) variable or one-byte STRING value that is used as an INT value
is left-filled with binary zeroes. Conversely, the high-order bits of an INT value are lost
if the value is moved to an UNSIGNED variable that is less than 16 bits, or to a one-
byte STRING variable (see Example 15-2 on page 15-4 and Example 15-3 on
page 15-4).
i := s; ! OK: INT and STRING are compatible
r := j; ! OK: r and j are both 32 bits
u1 := s; ! OK: UNSIGNED(1-16) is treated as INT
f := t; ! OK: f and t are both 64 bits
j := u2; ! OK: j and u2 are both 32 bits
r := i; ! ERROR: r is 32 bits, i is 16 bits
t := r; ! ERROR: t is 64 bits, r is 32 bits
Example 15-2. INT, STRING, and UNSIGNED Assignments (pTAL)
INT i := 3;
STRING s;
UNSIGNED(12) u1;
UNSIGNED(24) u2;
s := i + 1; ! OK: Assignment of INT to STRING
i := s + %H20; ! OK: Assignment of STRING to INT
u1 := i + s; ! OK: INT + STRING
u2 := i; ! ERROR: INT and UNSIGNED(17-31)
! are not assignment-compatible
Example 15-3. INT(32) and UNSIGNED(31) Assignments (pTAL)
INT(32) i;
UNSIGNED(31) u;
INT j;
i := u; ! OK: No bits are lost in the assignment
u := i; ! WARNING: Most significant bit of i could be lost
u := j; ! ERROR: INT and UNSIGNED(17-31)
! are not assignment compatible
Example 15-1. Valid and Invalid Assignments (TAL) (page 2 of 2)