pTAL Guidelines for TAL Programmers
Differences Between TAL and pTAL
pTAL Guidelines for TAL Programmers—527256-002
3-17
Declaring Procedure Pointer Formal Parameters
In Example 3-9 on page 3-16, the TAL compiler cannot verify that p1 has the same
attributes and parameter definitions as the procedure called from p2; therefore, you
must ensure that the procedure you pass to p2 has the same number of parameters,
the same parameter types, and the same procedure attributes as the procedure that
p2 expects when it calls its parameter, p.
As Example 3-9 on page 3-16 also shows, if you call a variable or extensible procedure
(in this case, p1), you must explicitly build a parameter mask and push it onto the stack
along with a parameter count word.
In pTAL, you pass a procedure that specifies a VARIABLE, EXTENSIBLE, or
RETURNSCC attribute only to a PROCPTR formal parameter, not to a PROC formal
parameter.
Declaring Procedure Pointer Formal Parameters
In both TAL and in pTAL, you can declare formal parameters of type PROCPTR. By
using procedure pointer parameters, the TAL and native compilers can:
•
Ensure that the attributes and parameters of procedures that you pass as actual
arguments match those of the procedures that you call using the procedure pointer
parameter
•
Build a parameter mask for calls to variable and extensible procedures
Example 3-10 on page 3-17 uses a procedure pointer to code the algorithm in
Example 3-9 on page 3-16.
Example 3-10. Passing an EXTENSIBLE Procedure to a PROCPTR Formal
Parameter
PROC p1 (i, j) EXTENSIBLE;
INT i, j;
EXTERNAL;
PROC p2(p);
PROCPTR p(a, b) EXTENSIBLE;
INT a, b;
END PROCPTR;
BEGIN
CALL p(, 1);
END;
PROC p3;
BEGIN
CALL p2(p1);
END;