pTAL Reference Manual (G06.24+, H06.09+, J06.03+)

The following rules apply to assignment statements:
The data type of the expression on the right side of an assignment statement must be compatible
with the data type of the destination on the left side of the assignment statement.
You cannot store a value into the implicit pointer of an indirect array or indirect structure.
You cannot store a value into the implicit pointer of an equivalenced variable that references
the data of an indirect array or indirect structure.
Do not depend on whether the left side or the right side of an assignment statement is evaluated
first.
Address types must match.
pTAL disallows all assignments of unlike data types except the following:
STRING and UNSIGNED(1-16) variables are syntactically and semantically equivalent
to INT variables. Thus, STRING and UNSIGNED(1-16) variables are valid anywhere an
INT variable is valid.
An UNSIGNED(1-16) variable or one-byte STRING value that is used as an INT value is
left-filled with binary zeros. Conversely, the high-order bits of an INT value are lost if the
value is stored in an UNSIGNED variable that is less than 16 bits, or to a one-byte STRING
variable, as shown in the following examples:
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
When an INT variable is assigned to a STRING variable, the upper 8 bits of the INT
variable are not retained in any way in the STRING variable. Thus, the comparison of
i1 to i2 in the final statement of the following code fails because i2 still holds the full
16 bits that were assigned to it at the beginning of the code, but i1 holds only the lower
8 bits. The upper 8 bits of I1 are not transferred to s in the assignment statement s :=
i1.
INT i1 := %HFFFF,
i2;
STRING s;
i2 := i1; ! Copy i1 to i2
s := i1; ! Assign 16-bit INT to 8-bit STRING
i1 := s; ! Assign 8-bit STRING to 16-bit INT
IF i1 = i2 THEN; ! i1 (%HFF) is not equal to i2 (%HFFFF)
UNSIGNED(17-31) variables are syntactically and semantically equivalent to INT(32)
variables. Thus, UNSIGNED(17-31) variables are valid anywhere INT(32) variables are
valid:
INT(32) i;
UNSIGNED(31) u;
INT j;
I := u; ! OK: No bits are lost in assignment
u := i; ! WARNING: Most significant bit of i could
! be lost
u := j; ! ERROR: INT and UNSIGNED(17-31) are not
! assignment-compatible
202 Statements