pTAL Guidelines for TAL Programmers
Coding Guidelines
pTAL Guidelines for TAL Programmersā527256-002
2-33
Dynamic Procedure Calls
In pTAL, your program traps with an Instruction Failure if a function attempts to return
because it arrives at the end of the function code. You must return from a function by
explicitly executing a RETURN statement.
Dynamic Procedure Calls
Guideline: Use procedure pointers instead of CODE (DPCL) statements.
In TAL, you can determine at run time which of several procedures to call. You can use
a TNS dynamic procedure call machine instruction (DPCL) to call the procedure in a
CODE statement, as in Example 2-34 on page 2-33.
Example 2-34 on page 2-33 does not work in pTAL, because pTAL does not support
STACK or CODE statements. Use procedure pointers to achieve the same effect.
If the procedure name you pass as an actual parameter does not specify a VARIABLE,
EXTENSIBLE, or RETURNSCC attribute, you can avoid CODE(DPCL) instructions by
using PROC parameters, as in Example 2-35 on page 2-34.
Note. If you compile your program with the DO_PTAL Directive on page 3-5, functions that
execute down to the END that closes a functionās body do not cause the program to abort.
DO_PTAL with the SYNTAX option is intended to help you convert from TAL to pTAL. Do not
rely on this directive for production code, because your pTAL program will have different
characteristics when it is a TNS process than when it is a native process.
Example 2-34. Dynamic Procedure Calls With CODE Statements (TAL Only)
PROC x1(p1, p2);
INT p1, p2;
BEGIN
...
END;
PROC x2(p1, p2);
INT p1, p2;
BEGIN
...
END;
PROC x3(p1, p2);
INT p1, p2;
BEGIN
...
END;
STACK param1;
STACK param2;
CODE (PUSH %711);
STACK procedure_address; ! @x1, @x2, or @x3
CODE (DPCL);