HP Pascal/iX Programmer's Guide (31502-90023)

7- 4
j : shortint;
i : integer;
PROCEDURE show_anyvar_alignment
(ANYVAR anyvar_parm : shortint);
EXTERNAL;
BEGIN
show_anyvar_alignment(c); {illegal -- must be 2-byte-aligned}
show_anyvar_alignment(j); {legal}
show_anyvar_alignment(i); {legal -- references high-order 2 bytes}
END.
When HP Pascal passes an actual parameter to a formal ANYVAR parameter,
it also passes a hidden parameter. The hidden parameter can be used to
determine the size of the actual parameter. See "Hidden Parameters"
for more information.
READONLY Parameters
A READONLY parameter is similar to a value parameter in that the routine
cannot directly modify its actual parameter, which can be a constant, an
expression, or a variable. READONLY differs from a value parameter in
that the routine cannot modify the formal parameter: you cannot assign a
value to the formal READONLY parameter, pass it to a VAR or ANYVAR
parameter, or pass it to either of the predefined functions
addr
,
baddress
, or
waddress
.
A READONLY parameter is similar to a VAR or ANYVAR parameter in that its
actual parameter is passed by reference. If the actual parameter is an
expression or constant, a copy of its value is passed by reference.
Example
PROGRAM prog;
$STANDARD_LEVEL 'HP_MODCAL'$
TYPE
arraytype = ARRAY [1..10] OF integer;
CONST
arrayconst = arraytype [10 OF 0];
VAR
arrayvar : arraytype;
FUNCTION arrayfunc : arraytype; EXTERNAL;
PROCEDURE p ( valuep : arraytype;
VAR varp : arraytype;
READONLY readonlyp : arraytype); EXTERNAL;
BEGIN
p(arrayconst, {value is passed}
arrayconst, {illegal -- must be a variable}
arrayconst); {address of copy of value is passed}
p(arrayvar, {value is passed}
arrayvar, {address is passed}
arrayvar); {address is passed}
p(arrayfunc, {value is passed}
arrayfunc, {illegal -- must be a variable}
arrayfunc); {address of copy of value is passed}
END.
The comments in the preceding program explain the differences in passing
a constant (arrayconst), a variable (arrayvar), and an expression (a call
to the function arrayfunc) to a value parameter (valuep), a VAR parameter