pTAL Reference Manual (G06.24+, H06.09+, J06.03+)
result-expression
is an arithmetic or conditional expression that a function must return to the caller.
result-expression must be of the same return type as the data type specified in the
function header. The data type of a conditional expression is always INT. Specify
result-expression only when returning from a function.
If result-expression is any type except FIXED or REAL(64), a function can return both
result-expression and cc-expression.
Topics:
• Functions (page 224)
• Procedures and Subprocedures (page 225)
• Condition Codes (page 225)
Functions
Every function must include at least one RETURN statement. The compiler does not verify that every
path through a function’s code includes a RETURN statement; therefore, a function can reach the
end of its code without executing a RETURN statement. If this happens, the function returns zero.
Functions that return a condition code that is not based on the value returned by the function must
specify explicitly the condition code value to return to the function’s caller.
Example 172 RETURN Statements Nested in an IF Statement
INT PROC other (nuff, more); ! Function with return type INT
INT nuff;
INT more;
BEGIN
IF nuff < more THEN ! IF statement
RETURN nuff * more ! Return a value
ELSE
RETURN 0; ! Return a different value
END;
Example 173 RETURN Statement That Returns a Value and a Condition Code
INT PROC p (i);
INT i;
BEGIN
RETURN i, i - max_val; ! Return a value and a condition code
END;
If you call a function, rather than calling it in an expression, you can test the returned condition
code, as Example 174 (page 224) does.
Example 174 Testing a Condition Code
INT PROC p1 (i);
INT i;
BEGIN
RETURN i;
END;
INT PROC p2 (i);
INT i;
BEGIN
INT j := i + 1;
RETURN i, j;
END;
224 Statements