pTAL Reference Manual (H06.03+)
Statements
HP pTAL Reference Manual—523746-005
12-35
Functions
Topics:
•
Functions on page 12-35
•
Procedures and Subprocedures on page 12-36
•
Condition Codes on page 12-37
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.
If you call a function, rather than calling it in an expression, you can test the returned
condition code, as Example 12-34 on page 12-35 does.
Example 12-32. 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 12-33. 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;
Example 12-34. Testing a Condition Code (page 1 of 2)
INT PROC p1 (i);
INT i;
BEGIN
RETURN i;
END;










