P2024¶
- Code
P2024
- Message
Array dimension range is invalid
Array dimension ranges must have the minimum value less than or equal to the maximum value. An array dimension where the start index is greater than the end index is invalid.
Example¶
The following code will generate error P2024:
TYPE
MY_ARRAY : ARRAY [10..1] OF INT;
END_TYPE
This error occurs because the array dimension range [10..1] is invalid - the minimum value (10) is greater than the maximum value (1).
To fix this error, ensure the minimum value is less than or equal to the maximum value:
TYPE
MY_ARRAY : ARRAY [1..10] OF INT;
END_TYPE
This applies to all dimensions in multi-dimensional arrays, and to arrays declared inline in a variable block as well as to named array types:
TYPE
MATRIX : ARRAY [1..3, 1..4] OF REAL; (* Valid *)
INVALID_MATRIX : ARRAY [3..1, 1..4] OF REAL; (* Error: first dimension invalid *)
END_TYPE
PROGRAM main
VAR
inverted : ARRAY [10..1] OF INT; (* Error: minimum (10) > maximum (1) *)
END_VAR
END_PROGRAM
A dimension whose minimum equals its maximum is valid and declares one element:
TYPE
ONE_ELEMENT : ARRAY [0..0] OF INT; (* Valid: a single element at index 0 *)
END_TYPE
Each bound must also be a DINT, a value from -2147483648 to 2147483647.
A bound outside that range is invalid whether or not the range is in order:
PROGRAM main
VAR
wide : ARRAY [0..2147483648] OF BOOL; (* Error: 2147483648 is not a DINT *)
END_VAR
END_PROGRAM
Think IronPLC is wrong about this?
If you believe this diagnostic is incorrect, open an issue on GitHub with a small sample that demonstrates the problem.