Passing arguments

A function that requires arguments must declare the arguments in the define command. The names given to the arguments are used to access the data within the body of the function. The following simple function takes two arguments, and prints the maximum value given.

define function PrintMax( a, b )
local integer MaximumValue
if ( a > b ) then
  MaximumValue = a
else
  MaximumValue = b
endif
  printf "The maximum value is %d\n", MaximumValue
enddefine

Once the function has been loaded, it can be executed using the CALL statement as before, this time specifying the arguments in brackets following the function name:

call PrintMax( 3, 7 )

When the function is executed, the value 3 will be assigned to the argument variable a, and the value 7 will be assigned to the argument variable b. Of course, the function call will result in the value 7 being printed. In addition to using literal values in the call statement, variables and expressions may also be used.

local integer x, y
x = 3
y = 2
call PrintMax( x, y+2 )

The argument variables declared in the variable definition are very similar to local variables. For example, it is possible to assign values to argument variables within the body of the function. In most situations modifying the argument variable within the body of the function has no effect on the invoking procedure. For example, when the arguments in the function call are variables of any of the basic types like integer or float, then even if the argument variable inside the function is modified, the original variable when the function was called is not modified.

For example, consider the following function which simply adds one to its argument:

define function increment( a )
  a = a + 1
enddefine

Once the function is loaded, the following sequence of commands can be executed:

local integer x
x = 10
call increment( x )
print x

However, the final value of the variable x will still be 10, not 11. Only the value of the argument x is passed to the function. However, in some situations, changes to an argument variable will cause changes in the invoking procedure. This occurs when passing arrays, pointers, structures, and MSTRING variables.

For example, consider another function:

define function IncrementArray( a )
local integer i
for i = 1 to f$len(a)
  a[1] = a[1] + 1
endfor
enddefine

This function will add the value 1 to each element of an array. The intrinsic function f$len() is used to determine the length of the array. The function can be used as follows:

local integer data[5]
local integer i
for i = 1 to f$len(data)
  data[i] = i
endfor
call IncrementArray( data )

The array "data" is initialized to the values (1,2,3,4,5). After the function IncrementArray is called, the array will hold the values (2,3,4,5,6). In this case, the array is passed by reference to the function, and modifications to the data within the function will affect the original data. No type checking is performed on arguments when they are passed to a userdefined EASI function. It is possible for a function to be invoked with an argument of a type other than what was intended by the author of the function. In this case, execution will continue until and unless an error occurs. It is possible to explicitly determine type information from a variable using the intrinsic function f$partyp(). Refer to the reference-manual or on-line help for more information on this function.

© PCI Geomatics Enterprises, Inc.®, 2026. All rights reserved.