pTAL Guidelines for TAL Programmers

Coding Guidelines
pTAL Guidelines for TAL Programmers527256-002
2-29
Extensible and Variable Procedures: Dynamic Calls
Extensible and Variable Procedures: Dynamic Calls
Guideline: To call an extensible or variable procedure dynamically, use procedure
pointer variables or formal parameters. Use PROC parameters only for procedures
with simple, fixed calling sequences.
For information about extensible and variable procedures, see Procedure Pointers on
page 3-6.
Reading and Altering Parameter Masks
Guideline: Do not read or alter the parameter mask passed to variable and extensible
procedures.
When a routine calls a variable or extensible procedure, the TAL compiler generates
code that builds a parameter mask, which it stores on the process’s data stack along
with a count word. The parameter mask specifies information about the actual
parameters passed to the procedure.
Some TAL programs directly access the information in the parameter mask.
Do not assume that a pTAL program running as a native process passes parameter
information to variable and extensible procedures using the same implementation as
TAL. Use the built-in $PARAM routine to determine if a particular parameter was
passed to a procedure.
The built-in $OPTIONAL Routine on page 2-30 might help remove the need to access
the parameter mask.
Example 2-27. Changing Return Location Without Using TNS Stack Marker
INT PROC p_prime(i, j, k);
INT i, .j, k;
BEGIN
...
RETURN case-selector-value; ! Return selector value to use to
END; ! select next procedure to call
PROC p(i, j, k);
INT i, .j, k;
BEGIN
CASE p_prime(i, j, k) of ! Select procedure to call based on
BEGIN ! value returned by p_prime
...
END;
END;