pTAL Conversion Guide

Statements
pTAL Conversion Guide527302-002
15-20
Returning a Value and Condition Code in TAL
Returning a Value and Condition Code in TAL
The value of the condition code after returning from a function is based on the nature
of the expression in the RETURN statement as well as on the value returned by the
function.
If a function’s value is the result of a computation, comparison, or load of a numeric
value, the condition code is based on the sign of the value returned.
If a function’s value is exactly one byte, loaded to the TNS stack, the ASCII character
represented by the byte determines the value of the condition code as follows:
The following example shows the value of the condition code if the value returned by a
function is an uppercase “A”:
STRING s := "A";
RETURN s; ! Returns condition code "="
If a function’s value is an address generated by applying the @ operator to a variable
name, the value of the condition code prior to executing the RETURN statement is
returned to the function’s caller:
INT i;
i := 0; ! Sets condition code to "="
RETURN @s; ! Returns =, based on "i := 0"
If a function’s value is, in turn, the value returned by a TAL standard function, the
condition code depends on which standard function is executed and the actual
parameter passed to the standard function. In this case, the value of the condition code
is not well-defined.
Returning a Condition Code in pTAL
Procedures (but not functions) return a condition code only if the procedure declaration
includes the RETURNSCC attribute. The native compiler reports an error if a
procedure attempts to test the condition code after calling a procedure that does not
specify RETURNSCC.
Example 15-26. Returning a Value and a Condition Code (TAL)
INT PROC p(n);
INT n;
BEGIN
RETURN n; ! Return integer value
END; ! Condition code is set according to the value of n
ASCII Character Condition Code
Numeric <
Uppercase or lowercase alphabetic =
Other (special) character >