Open array parameters

Open array parameters

Language reference ›› Procedures and functions ››
Parent Previous Next

An open array parameter is a way to pass an array for which the dimension is not known, or to pass arrays with different sizes.



PROCEDURE Test(X: ARRAY OF integer);
 BEGIN
   FOR I := LOW(X) TO HIGH(X) DO
         X[I] := I * I;
 END;

VAR
 X0: ARRAY[1..5] OF integer;
 X1: ARRAY[-2..20] OF integer;

Test(X0);
Test(X1);


When an array is passed as an open array parameter, its bounds are shifted so that low bound is always zero, so the low() pseudo function applied to an open array always returns 0.

An open array parameter is always passed by address.

The open array pseudo variable (X in the example above) is allocated as a pointer but occupies also an additional stealth RAM space that is used to pass the actual high bound of the array.

Open arrays may be passed as an argument to another procedure or function.