HP Pascal/iX Reference Manual (31502-90022)

11- 23
through the use of the predefined functions sizeof and bitsizeof. This
additional size parameter is not passed when the routine option
UNCHECKABLE_ANYVAR is used.
This implicit reference type coercion is independent of the level of type
coercion selected when the actual parameter is used.
Example
TYPE
byte = 0..255;
byte_array = PACKED ARRAY [1..max_bound] OF byte;
VAR
int : integer;
rec : record_type;
PROCEDURE zero_bytes( ANYVAR arr : byte_array );
VAR
i : 0..max_bound;
limit : 1..max_bound;
BEGIN
IF (sizeof(arr) > max_bound) THEN
limit := max_bound
ELSE
limit := sizeof(arr);
FOR i := 1 TO limit DO
arr[i] := 0;
END;
BEGIN
zero_bytes( int );
zero_bytes( rec );
END;
READONLY.
This formal parameter mechanism protects the actual parameter from
modification within the procedure or function.
A formal READONLY parameter may not be:
* The target of an assignment statement.
* Passed as an argument to a VAR or ANYVAR parameter.
* Passed as an argument to the addr predefined function.
* Passed as an argument to any predefined routine that modifies that
argument.
In this way, modification of a variable passed as a READONLY parameter is
an error between the call to and return from the procedure or function by
modifying the formal parameter itself.
The actual parameter is passed by reference. If the actual parameter is
an expression or a constant, then a reference to a copy of the value is
passed.
Example
PROCEDURE proc( READONLY parm : integer );
VAR
pint : ^ integer;
PROCEDURE procx( VAR i : integer );
external;
BEGIN
...
parm := 0; { illegal : cannot assign to a READONLY }
procx( parm ); { illegal : cannot pass to a VAR parameter }
pint := addr( parm ); { illegal : cannot take its address }
...
END;