Functions / The runtime stack |
The following data types and structures are passed by value to a function:
When passing a function parameter by value, the runtime system pushes a copy of the data on the stack. As result, inside the function, the local variable receiving the parameter value can be changed without affecting the variable used by the caller.
MAIN DEFINE rec RECORD a INT, b VARCHAR(50) END RECORD CALL func_r(rec.*) CALL func_ab(rec.*) END MAIN -- Function defining a record like that in the caller FUNCTION func_r(r) DEFINE r RECORD a INT, b VARCHAR(50) END RECORD ... END FUNCTION -- Function defining two individual variables FUNCTION func_ab(a, b) DEFINE a INT, b VARCHAR(50) ... END FUNCTION
MAIN DEFINE arr ARRAY[5] OF INT CALL func(arr) END MAIN -- function defining same static array as the caller FUNCTION func(x) DEFINE x ARRAY[5] OF INT ... END FUNCTION
Note that dynamic arrays are passed by reference.