|
ARRAY |
|
|
An array is used to "group" a number of data elements together so that it can be referenced by an index.
An array can also be initialized - the exception being arrays declared in VAR_INPUT / VAR_OUTPUT or in a FUNCTION. In case an array is not fully initialized, the remaining elements in the array will simply be set to the default value 0 - FALSE by the compiler.
VPL supports one-dimensional and two-dimensional arrays with a maximum number of elements defined by the execution architecture. A one-dimensional array is declared as ARRAY [low..high] OF type. A two-dimensional array is declared as ARRAY [low1..high1, low2..high2] OF type. Arrays declared as global VAR_INPUT or VAR_OUTPUT variables can only be one-dimensional. Array bounds are inclusive and indexes must not be negative. A two-dimensional array is indexed by using both indexes, for example Matrix[2,3]. For two-dimensional arrays the second index changes fastest. Initial values are assigned in row-major order, so ARRAY [1..2, 1..3] receives values for [1,1], [1,2], [1,3], [2,1], [2,2], and [2,3]. The total number of elements in a two-dimensional array is the size of the first dimension multiplied by the size of the second dimension. SIZEOF(ArrayName) returns the total storage size of the array, while SIZEOF(ArrayName[i,j]) returns the size of one element. Under X32/NX32 the maximum total number of elements is 65535 and the maximum size of each element is also 65535. Under the NX32L execution the actual number and size of the defined arrays are limited by the available memory.
Arrays can be supplied to functions by access using an ACCESS ARRAY parameter in the function VAR_INPUT section. The function receives direct access to the caller's array storage; the array is not copied. For one-dimensional ACCESS ARRAY parameters, a larger actual array is accepted when its bounds fully cover the formal bounds. For two-dimensional ACCESS ARRAY parameters, dimensions and bounds must match exactly.
ACCESS ARRAY function parameter example: FUNCTION ClearRange : INT;
One-dimensional array Example: INCLUDE rtcu.inc
Two-dimensional array example: VAR |