14.4.1 Value parameters

Value parameters are declared as follows:

Value parameters

value parameter ------identifier list-:--------------parameter type------
              |                  -array -of--|                 |
              -identifier- :- type identifier = -default parameter value

When parameters are declared as value parameters, the procedure gets a copy of the parameters that the calling statement passes. Any modifications to these parameters are purely local to the procedure’s block, and do not propagate back to the calling block.

A block that wishes to call a procedure with value parameters must pass assignment compatible parameters to the procedure. This means that the types should not match exactly, but can be converted to the actual parameter types. This conversion code is inserted by the compiler itself.

Care must be taken when using value parameters: value parameters makes heavy use of the stack, especially when using large parameters. The total size of all parameters in the formal parameter list should be below 32K for portability’s sake (the Intel version limits this to 64K).

Open arrays can be passed as value parameters. See section 14.4.5, page 742 for more information on using open arrays.

For a parameter of a simple type (i. e. not a structured type), a default value can be specified. This can be an untyped constant. If the function call omits the parameter, the default value will be passed on to the function. For dynamic arrays or other types that can be considered as equivalent to a pointer, the only possible default value is Nil.

The following example will print 20 on the screen:

program testp;  
  MyConst = 20;  
Procedure MyRealFunc(I : Integer = MyConst);  
  Writeln(’Function received : ’,I);