pTAL Reference Manual (G06.24+, H06.09+, J06.03+)
CALL p1 (i);
IF < THEN ... ; ! Test return value
CALL p2 (i);
IF < THEN ... ; ! Test condition code
Procedures and Subprocedures
In procedures and subprocedures that are not functions, a RETURN statement is optional. A
nonfunction procedure or subprocedure that returns a condition code value, however, must return
to the caller by executing a RETURN statement that includes cc-expression.
In a procedure designated MAIN, a RETURN statement stops execution of the procedure and
passes control to the operating system.
Procedures that return a condition code must specify explicitly the value of the condition code to
return to the procedure’s caller. In general, a procedure or subprocedure returns control to the
caller when:
• A RETURN statement is executed.
• The called procedure or subprocedure reaches the end of its code.
Example 175 RETURN Statement in a Procedure
PROC something;
BEGIN
INT a,
b;
! Manipulate a and b
IF a < b THEN
RETURN; ! Return to caller
! Lots more code
END;
The procedure in Example 176 (page 225) returns a condition code that indicates whether an add
operation overflows.
Example 176 RETURN Statement in a Procedure That Returns a Condition Code
PROC p (s, x, y) RETURNSCC;
INT .s, x, y;
BEGIN
INT cc_result;
INT i;
i := x + y;
IF $OVERFLOW THEN cc_result := 1
ELSE cc_result := 0;
s := i;
RETURN cc_result; ! If overflow, condition code is >;
END; ! otherwise, it is =
Condition Codes
A procedure (but not a function) returns a condition code only if the procedure declaration includes
the RETURNSCC attribute. The compiler reports an error if a procedure attempts to test the condition
code after calling a procedure that does not specify RETURNSCC.
RETURN 225