HP 3000 Manuals

EXTENSIBLE [ HP Pascal/iX Programmer's Guide ] MPE/iX 5.0 Documentation


HP Pascal/iX Programmer's Guide

EXTENSIBLE 

The EXTENSIBLE routine option identifies a procedure that has an
extensible parameter list.

An extensible parameter list has a fixed number of nonextension
parameters and a variable number of extension parameters.  The integer n 
after the keyword EXTENSIBLE specifies that the first n parameters in the
formal parameter list are nonextension parameters (n can be zero).  Any
other parameters are extension parameters.

A nonextension parameter is required.  Every call to the routine must
provide an actual parameter for it.

An extension parameter is optional.  A call to the routine can omit its
actual parameter from the actual parameter list.  However, if the actual
parameter list contains an actual parameter for the xth extension
parameter, it must contain actual parameters for those before it.


NOTE You can pass only level 1 procedures to EXTENSIBLE. You cannot pass large (greater than 8 bytes) value parameters to an extension parameter.
Example PROGRAM prog; $STANDARD_LEVEL 'EXT_MODCAL'$ VAR b : boolean; FUNCTION f (i,j : integer) : boolean OPTION EXTENSIBLE 2; {both parameters are required} BEGIN . . END; PROCEDURE p (x,y : integer) OPTION EXTENSIBLE 0; {no parameters are required} BEGIN . . END; PROCEDURE q (a : integer; b : real; c : char; d : integer) OPTION EXTENSIBLE 2; {first two parameters are required} BEGIN . . END; (Example is continued on the next page.) BEGIN b := f(36,45); {legal} b := f(20); {illegal} b := f(,66); {illegal} b := f; {illegal} p; {legal} p(); {legal} p(100); {legal} p(250,13); {legal} p(,60); {illegal} q(5,9.4); {legal} q(4,3.0,'z'); {legal} q(7,8.8,'w',55); {legal} q(2,1.1,,93); {illegal} q(,); {illegal} q(,,45); {illegal} q(400,,22); {illegal} END. Both parameters of the function f are nonextension parameters. Every call to f must specify actual parameters for them. Both parameters of the procedure p are extension parameters. A call to p can specify or omit actual parameters for them. If the second actual parameter is specified, the first must also be specified. The first two parameters of the procedure q are nonextension parameters; the last two are extension parameters. A call to q must specify actual parameters for the first two parameters, but it can specify or omit actual parameters for the last two parameters. If the fourth actual parameter is specified, the third must also be specified. The number of extension parameters in an extensible parameter list is flexible: you can add new ones later, and you need not recompile programs that call the routine. The updated version of the routine can use the predefined function haveextension to determine whether it was passed values for specific extension parameters. Without the DEFAULT_PARMS procedure option, the predefined function haveextension returns true and false under these conditions: ------------------------------------------------------------------------------------- | | | | | Function | Returns true | Returns false | | | | | ------------------------------------------------------------------------------------- | | | | | haveextension(x) where x | If the routine was passed | If the routine was not | | is a formal parameter of | an actual parameter for | passed an actual | | the routine that called | x. | parameter for x. | | haveextension. | | | | | | | -------------------------------------------------------------------------------------
NOTE A parameter cannot be referenced when haveextension would return false.
Example The procedure p has two nonextension parameters: PROCEDURE p (n1,n2 : integer) OPTION EXTENSIBLE 2; BEGIN {p} . . END; {p} The program oldprog calls the procedure p: PROGRAM oldprog; PROCEDURE p (n1,n2 : integer) OPTION EXTENSIBLE 2; EXTERNAL; BEGIN p(1,2); END. The procedure p is updated and two new parameters are added. It uses the predefined function haveextension to determine whether its two new extension parameters were passed to it. PROCEDURE p (n1,n2,e1,e2 : integer) OPTION EXTENSIBLE 2; BEGIN {p} IF haveextension(e1) AND haveextension(e2) THEN BEGIN . . END; END; {p} The procedure p must be recompiled, but the program oldprog need not be. Its call to p is still legal, as is the call to p from the program newprog: PROGRAM newprog; PROCEDURE p (n1,n2,e1,e2 : integer) OPTION EXTENSIBLE 2; EXTERNAL; BEGIN p(1,2,3,4); END. A call to a routine with an extensible parameter list contains a hidden parameter. See Chapter 7 for details.
NOTE A routine with n extensible parameters is not the same as a procedure with n parameters that does not have EXTENSIBLE, even if the two procedures are otherwise identical. For example, these procedures are not the same: PROCEDURE proc (a,b : char) PROCEDURE proc (a,b : char); OPTION EXTENSIBLE 2; BEGIN BEGIN END; END;


MPE/iX 5.0 Documentation