Parameter Passing Mechanism

Parameters are passed to IDL system and user-written procedures and functions by value or by reference. It is important to recognize the distinction between these two methods.

Parameters passed by value can only be inputs to program units. Results cannot be passed back to the caller by these parameters. Parameters passed by reference can convey information in either or both directions. For example, consider the following 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 following call does nothing because a value cannot be stored in the constant 4, which was passed by value.

ADD, 4, A 

No error message is issued. Similarly, if ARR is an array, the call

ADD, ARR[5], 4 

will not achieve the desired effect (adding 4 to element ARR[5]), because subscripted variables are passed by value. The correct, though somewhat awkward, method is as follows:

TEMP = ARR[5] 
ADD, TEMP, 4 
ARR[5] = TEMP 

Note
IDL structures behave in two distinct ways. Entire structures are passed by reference, but individual structure fields are passed by value. See Parameter Passing with Structures for additional details.