pTAL Guidelines for TAL Programmers

Coding Guidelines
pTAL Guidelines for TAL Programmers527256-002
2-50
Condition Code: Saving the Value in a Variable
Condition Code: Saving the Value in a Variable
Guideline: Do not save the value of a condition code by assigning its value to a
variable.
In TAL, you can assign the condition code to a variable. The assignment statement in
Example 2-63 on page 2-50 stores a TRUE value (-1) in i if the condition code is CCE,
and stores FALSE (0) in i otherwise.
In pTAL, you cannot assign the value of the condition code to a variable; therefore, the
assignment statement in Example 2-63 on page 2-50 is not valid in pTAL. If you must
save the value of the condition code, test it and set a variable to a value that
corresponds to the condition code value, as in Example 2-64 on page 2-50.
Example 2-62. Returning a Condition Code
INT PROC p;
BEGIN
RETURN int_value;
END;
REAL PROC q;
BEGIN
RETURN real_value;
END;
CALL p;
IF <> THEN ... ! OK: p returns value of type INT
CALL q;
IF <> THEN ... ! ERROR: q returns value of type REAL
Example 2-63. Assigning a Condition Code to a Variable (TAL Only)
INT i;
i := =;
Example 2-64. Setting a Variable to Reflect a Condition Code
LITERAL cc_eql = -1,
cc_lss = 0,
cc_gtr = -1;
INT cond_code,
i := 0;
...
i := i - 1;
IF < THEN cond_code := cc_lss
ELSE IF = THEN cond_code := cc_eql
ELSE cond_code := cc_gtr;