Free Pascal supports the passing of open arrays, i.e. a procedure can be declared with an array of unspecified length as a parameter, as in Delphi. Open array parameters can be accessed in the procedure or function as an array that is declared with starting index 0, and last element index High(parameter). For example, the parameter
would be equivalent to
Where N would be the actual size of the array that is passed to the function. N-1 can be calculated as High(Row).
Specifically, if an empty array is passed, then High(Parameter) returns -1, while low(Parameter) returns 0.
Open parameters can be passed by value, by reference or as a constant parameter. In the latter cases the procedure receives a pointer to the actual array. In the former case, it receives a copy of the array. In a function or procedure, open arrays can only be passed to functions which are also declared with open arrays as parameters, not to functions or procedures which accept arrays of fixed length. The following is an example of a function using an open array:
As of FPC 2.2, it is also possible to pass partial arrays to a function that accepts an open array. This can be done by specifying the range of the array which should be passed to the open array.
Given the declaration
the following call will compute and print the average of the 100 numbers:
But the following will compute and print the average of the first and second half: