Parameter Passing Mechanism
Parameters are passed to system and user-written procedures and functions by value or by reference. It is important that you recognize the distinction between these two methods.
Expressions, constants, system variables, and subscripted variable references are passed by
value.
Variables are passed by
reference.
Parameters passed by value may only be inputs to program units; results may not be passed back to the caller via these parameters. Parameters passed by reference may convey information in either or both directions. For example consider this trivial procedure:
PRO ADD, A, B
A = A + B
RETURN
END
This procedure adds its second parameter to the first, returning the result in the first. The call:
ADD, A, 4
adds 4 to A and stores the result in variable A. The first parameter is passed by reference and the second parameter, a constant is passed by value. The call:
ADD, 4, A
does nothing because a value may not be stored in the constant “4” which was passed by value. No error message is issued.
Similarly, if ARR is an array, the call:
ADD, ARR(5), 4
does not achieve the desired effect (adding 4 to element ARR (5)) because subscripted variables are passed by value. A possible alternative is:
TEMP = ARR(5)
ADD, TEMP, 4
ARR(5) = TEMP
Version 2017.0
Copyright © 2017, Rogue Wave Software, Inc. All Rights Reserved.