Hidden Parameters [ HP Pascal/iX Programmer's Guide ] MPE/iX 5.0 Documentation
HP Pascal/iX Programmer's Guide
Hidden Parameters
Hidden parameters do not appear in formal or actual parameter lists, but
are nevertheless passed to routines. They are always integers.
You must know about hidden parameters in order to debug your program at
the assembly language level, and you must include them in the parameter
lists of external routines that are not written in Pascal. (For
information, see Chapter 9 .)
Table 7-3 shows which routines receive hidden parameters, how many
hidden parameters they receive, where the hidden parameters are in the
physical parameter order, and the values of the hidden parameters.
Table 7-3. Hidden Parameters
-------------------------------------------------------------------------------------------------
| | | | |
| Routine With | Receives | Location of Hidden | Value of [Each] |
| | | Parameters in | Hidden Parameter |
| | | Physical Order | |
| | | | |
-------------------------------------------------------------------------------------------------
| | | | |
| ANYVAR parameters | One hidden parameter | Each one follows its | Size in bytes of the |
| | for each ANYVAR | corresponding ANYVAR | actual parameter. |
| | parameter. | parameter. | |
| | | | |
-------------------------------------------------------------------------------------------------
| | | | |
| Generic string | One hidden parameter | Each one follows its | Maximum length of |
| parameters (not | for each generic | corresponding generic | string. |
| (PACs) | string parameter. | string parameter. | |
| | | | |
-------------------------------------------------------------------------------------------------
| | | | |
| Extensible parameter | One hidden parameter. | First parameter. | Number of actual |
| list | | | parameters passed |
| | | | (excluding hidden |
| | | | parameters). |
| | | | |
-------------------------------------------------------------------------------------------------
| | | | |
| Multi-dimensional | One hidden parameter | Each one follows | Element size, in |
| conformant array | for each nested | bounds values of | units meaningful to |
| parameters | conformant array. | corresponding nested | the code that indexes |
| | | conformant array. | the array. |
| | | | |
-------------------------------------------------------------------------------------------------
| | | | |
| Routine parameters | One hidden parameter | Last parameters. | Static link for |
| | for each routine | | containing routine. |
| | parameter. | | |
| | | | |
-------------------------------------------------------------------------------------------------
| | | | |
| External SPL variable | One hidden parameter | First parameter | Same as SPL |
| | | | |
-------------------------------------------------------------------------------------------------
ANYVAR Parameters
If a routine has ANYVAR parameters, its physical parameter order contains
one hidden parameter for each. In the physical parameter order, each
hidden parameter follows its corresponding ANYVAR parameter. The value
of each hidden parameter is the size of the corresponding ANYVAR
parameter (in bytes).
If the routine specifies the UNCHECKABLE_ANYVAR option, no hidden
parameters are passed for ANYVAR parameters.
The UNCHECKABLE_ANYVAR option is used when calling routines that were not
written in Pascal.
Example 1
$STANDARD_LEVEL 'HP_MODCAL'$
PROGRAM prog;
VAR
x,y,z : integer;
PROCEDURE p ( a : integer;
ANYVAR b, c : integer;
d : integer;
ANYVAR e : integer);
BEGIN {p}
.
.
.
END; {p}
BEGIN {prog}
x := 2;
y := 3;
z := 5;
p(1,x,y,4,z);
END. {prog}
Including hidden parameters ( highlighted), the parameter list that
appears as p(1,x,y,4,z) in the preceding program is:
-------------------
| |
| Value 1 |
| |
-------------------
| |
| Address of x |
| |
-------------------
| |
| Size of x |
| |
-------------------
| |
| Address of y |
| |
-------------------
| |
| Size of y |
| |
-------------------
| |
| Value 4 |
| |
-------------------
| |
| Address of z |
| |
-------------------
| |
| Size of z |
| |
-------------------
You can access these hidden parameters with the predefined functions
bitsizeof and sizeof. If the UNCHECKABLE_ANYVAR procedure option is
specified, bitsizeof and sizeof return the size of the formal parameter
(for more information on UNCHECKABLE_ANYVAR, see Chapter 8 ).
Example 2
$STANDARD_LEVEL 'EXT_MODCAL'$
PROGRAM prog (output);
TYPE
t1 = ARRAY [1..20] OF integer;
t2 = ARRAY [1..11] OF integer;
VAR
v : t1;
PROCEDURE p1 (ANYVAR parm : t2);
BEGIN {p1}
writeln('Size of actual parameter = ', sizeof(parm):1);
writeln('Bit size of actual parameter = ', bitsizeof(parm):1);
END; {p2}
PROCEDURE p2 (ANYVAR parm : t2);
OPTION UNCHECKABLE_ANYVAR;
BEGIN {p2}
writeln('Size of formal parameter = ', sizeof(parm):1);
writeln('Bit size of formal parameter = ', bitsizeof(parm):1);
END; {p2}
BEGIN {prog}
p1(v);
p2(v);
END. {prog}
The preceding program prints:
Size of actual parameter = 80
Bit size of actual parameter = 640
Size of formal parameter = 44
Bit size of formal parameter = 352
The procedure p1 does not specify the option UNCHECKABLE_ANYVAR, so it
can access the hidden parameter associated with the actual parameter v.
The functions sizeof(parm) and bitsizeof(parm) return the size of the
actual parameter v.
The procedure p2 specifies the option UNCHECKABLE_ANYVAR, so it cannot
access the hidden parameter associated with the actual parameter v,
because it is omitted from the physical parameter order. The functions
sizeof(parm) and bitsizeof(parm) return the size of the formal parameter
parm (that is, the sizes of the type t2).
Generic String Parameters
If a routine has generic string parameters, its physical parameter order
contains one hidden parameter for each. In the physical parameter order,
each hidden parameter follows its corresponding actual string parameter.
The value of each hidden parameter is the maximum length of the
corresponding actual string parameter.
Extensible Parameter List
If a routine has an extensible parameter list, its physical parameter
order begins with a hidden parameter. The value of the hidden parameter
is the number of actual parameters passed, excluding hidden parameters.
This value is always greater than or equal to the number of nonextension
parameters, because the routine must have a value for each of them.
Example
$STANDARD_LEVEL 'EXT_MODCAL'$
PROGRAM prog;
PROCEDURE p (x : integer;
y : real);
OPTION EXTENSIBLE 1
DEFAULT_PARMS (x := 0,
y := 1.0);
BEGIN
.
.
END;
BEGIN
p; {value of hidden parameter is one}
p(9); {value of hidden parameter is one}
p(9, 2.7); {value of hidden parameter is two}
p(, 2.7); {value of hidden parameter is two}
END.
The procedure p has one nonextension parameter, so the value of the
hidden parameter for any call to p is at least one.
In the first call above, p receives one value from DEFAULT_PARMS; the
value of the hidden parameter is one.
In the second call, p receives one value from the actual parameter list;
the value of the hidden parameter is one.
In the third call, p receives two values from the actual parameter list;
the value of the hidden parameter is two.
In the fourth call, p receives one value from DEFAULT_PARMS and one from
the actual parameter list; the value of the hidden parameter is two. For
more information on OPTION EXTENSIBLE and OPTION DEFAULT_PARMS, see
Chapter 8 .
Multidimensional Conformant Array Parameters
If a routine has multidimensional conformant array parameters, its
physical parameter order contains one hidden parameter for each nested
conformant array element. In the physical parameter order, each hidden
parameter follows the actual parameters for the bounds of its
corresponding dimension. The value of each hidden parameter is the size
of its corresponding dimension. These hidden parameters are not
accessible to the programmer. The program uses them to calculate values
of the sizeof function.
Example
PROGRAM prog;
TYPE
t = 1..10;
VAR
a : ARRAY [1..3,1..8,1..4] OF integer;
PROCEDURE p (b : ARRAY [lb1..ub1 : t;
lb2..ub2 : t;
lb3..ub3 : t] OF integer; EXTERNAL;
BEGIN
p(a);
END.
The call p(a) passes two hidden parameters to p, one for each nested
conformant array dimension. Including hidden parameters ( highlighted),
the parameter list that appears in the preceding program as p(a) is:
-------------------------
| |
| Address of a |
| |
-------------------------
| |
| Value 1 (lb1) |
| |
-------------------------
| |
| Value 3 (ub1) |
| |
-------------------------
| |
| Value 1 (lb2) |
| |
-------------------------
| |
| Value 8 (ub2) |
| |
-------------------------
| |
| (UB2-LB2+1) *(UB3) |
| |
-------------------------
| |
| Value 1 (lb3) |
| |
-------------------------
| |
| Value 4 (ub3) |
| |
-------------------------
| |
| (UB3) |
| |
-------------------------
Routine Parameters
If a routine has routine parameters, its physical parameter order
contains one hidden parameter for each routine parameter. (This is not
true of parameters that are routine variables.) These hidden parameters
are at the end of the physical parameter order, in the same order as
their corresponding routine parameters. The value of a hidden parameter
for a specific routine parameter is the static link. This static link
allows access to the variables and parameters of the enclosing routines.
NOTE Level one routines do not require static links. Therefore, they
are the only type of routine parameters that can be passed to
extensible parameters.
Example
PROGRAM prog (input,output);
PROCEDURE p (PROCEDURE param1 (x : integer);
PROCEDURE param2 (y : integer);
FUNCTION param3 (z : integer) : integer;
v : integer);
VAR
i : integer;
BEGIN {p}
param1(v);
param2(v);
i := param3(v);
END; {p}
PROCEDURE actual1 (a : integer);
PROCEDURE actual2 (b : integer);
FUNCTION actual3 (c : integer) : integer;
BEGIN {actual3}
p(actual1,actual2,actual3,100);
END; {actual3}
BEGIN {actual2}
.
.
END; {actual2}
BEGIN {actual1}
.
.
END; {actual1}
BEGIN
.
.
.
END.
Including hidden parameters ( highlighted), the physical parameter order
that appears in the preceding program as p(actual1,actual2,actual3,100)
is:
-----------------------------------------------------------
| |
| Procedure label for procedure actual1 |
| |
-----------------------------------------------------------
| |
| Procedure label for procedure actual2 |
| |
-----------------------------------------------------------
| |
| Function label for function actual3 |
| |
-----------------------------------------------------------
| |
| Value 100 |
| |
-----------------------------------------------------------
| |
| Static link for procedure actual1 (nil) |
| |
-----------------------------------------------------------
| |
| Static link for procedure actual2 (actual1's locals) |
| |
-----------------------------------------------------------
| |
| Static link for function actual3 (actual2's locals) |
| |
-----------------------------------------------------------
EXTERNAL SPL VARIABLE
The EXTERNAL SPL VARIABLE directive causes the compiler to pass a hidden
parameter that specifies the presence of parameters. The hidden
parameter is a 32 bit integer with the mask right justified as required
by SPL/V.
Example
program prog1;
var count : integer;
procedure ext_spl(p1, p2, p3 : integer);
external spl variable;
begin
ext_spl(1,,count);
ext_spl(1);
end.
Including hidden parameters (highlighted), the physical parameter order
that appears in the preceding program as ext_spl(1,,i) is:
--------------------------
| |
| Value 5 |
| |
--------------------------
| |
| Value 1 |
| |
--------------------------
| |
| Value 0 (space |
| holder) |
| |
--------------------------
| |
| Value of count |
| |
--------------------------
MPE/iX 5.0 Documentation