pTAL Conversion Guide

Statements
pTAL Conversion Guide527302-002
15-19
RETURN Statement
RETURN Statement
A RETURN statement causes a routine to return control to its caller. When you return
from a function, the RETURN statement also specifies a value to return to the
function’s caller.
Topics:
RETURN Statement on page 15-19
Returning a Value and Condition Code in TAL on page 15-20
Returning a Condition Code in pTAL on page 15-20
RETURN Statement
TAL
A RETURN statement is not required in a function body. The TAL compiler reports a
warning if a function does not have a RETURN statement, but it continues compiling
and produces executable code if it does not detect errors. The function returns 0 to its
caller when it reaches the end of its code.
pTAL
Every function must include at least one RETURN statement, although the native
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, in which case the
program traps with an Invalid Instruction run-time error. If pTAL generates the code for
Example 15-25 on page 15-19 and i is greater than or equal to 0, the program traps
upon reaching the END at the end of ps code.
Note. In the discussion of the RETURN statement, the word “procedure” implies both
procedures and subprocedures but not functions.
Example 15-25. RETURN Statement
INT PROC p(i);
INT i;
BEGIN
IF i < 0 THEN RETURN 1; ! Return 1 if i < 0
END; ! Otherwise, return 0