Passing Arrays as Arguments
Arrays can be passed between functions:
Function1()() INT[] intArray; INT[][] intArray2; STRING[] stringArray; Function2(intArray, stringArray)(intArray2); END; Function2(INT[] intArray, STRING[] stringArray)(INT[][] intArray2) // ... END;
Input Parameters
Arrays passed as input parameters are passed by value (and a deep copy of all the data will be made). Array elements may be passed as input parameters. Changes made to the array contents and variable reassignment will not be seen by the calling code:
Function1()() INT[] array; array[0] := 10; Function2(array)(); PRINT("array[0]: ", array[0], "\n"); END; Function2(INT[] inputArray)() INT[] otherArray; inputArray[0] := 42; otherArray[0] := 99; inputArray := otherArray; END;
array[0]: 10
Output Parameters
Like other variable types, arrays passed as output parameters are passed by reference: changes made to the array contents and variable reassignment will be seen by the calling code:
Function1()() INT[] array1, array2; array1[0] := 10; array2[0] := 10; Function2()(array1, array2); PRINT("array1[0]: ", array1[0], "\n"); PRINT("array2[0]: ", array2[0], "\n"); END; Function2()(INT[] array1, INT[] array2) INT[] otherArray; otherArray[0] := 42; array1[0] := 99; array2 := otherArray; END;
array[0]: 99 array[0]: 42
Passing an array element as an output parameter:
Function1()() INT[] array := { 0, 1 }; SubArrayFunction()(array[0]); PRINT(array[0]); END; SubArrayFunction()(INT value) value := 10; END;
10
See Also
XJTAG v4.2.5
