Parameter Passing

If a library program declares a parameter to be call-by-name, the calling program can declare the parameter to be call-by-name, call-by-reference, or call-by-value. If a library program declares a parameter to be call-by-reference, the calling program can declare the parameter to be call-by-name, call-by-reference, or call-by-value. If a library program declares a parameter to be call-by-value, the calling program can declare the parameter only to be call-by-value. For pointer parameters, the parameter-passing mode of the library program and the client program must match exactly.

Parameter Passing Rules shows the parameter passing rules. In the table, the legal combinations of parameter passing modes are marked with a P for pointer parameters and an X for all other parameter types.

Table 14. Parameter Passing Rules

Library Program

 

Calling Program

 

Name

Reference

Value

Name

X

X

X

Reference

X

P

X

Value

   

P


In ALGOL programs, parameters are declared to be call-by-value, call-by-reference, or call-by-name. In ALGOL library programs, parameters to entry points that are declared to be call-by-value are described in the directory as call-by-value. Parameters declared to be call-by-reference are described in the directory as call-by-reference. Parameters declared to be call-by-name are described in the directory as call-by-reference, except for formal procedures and Boolean, complex, dinteger, double, integer, and real variables, which are described in the directory as call-by-name.

In ALGOL calling programs, parameters to entry points that are declared to be call-by-value are described in the template as call-by-value. Parameters declared to be call-by-reference are described in the template as call-by-reference. Parameters declared to be call-by-name are described in the template as call-by-reference, except for Boolean, complex, dinteger, double, integer, and real variables, which are described in the template as call-by-name.

An array parameter in ALGOL that is declared with any of its lower bounds as an asterisk (*) lower bound is described in the template or directory as N+1 parameters, where N is the number of dimensions of the formal array. The first parameter is the array itself, followed by the N lower bounds described as call-by-value integer variables.