P4077¶
- Code
P4077
- Message
Array initializer has more values than the array has elements
This error occurs when an array initializer gives more values than the array has elements.
An array initializer lists the values of the array’s elements in order. A
repeated value (3(0)) counts once for each repetition. The initializer
may give fewer values than the array has elements, in which case each
remaining element starts at its type’s default value, but it cannot give
more: there is no element for the extra values to initialize.
Example¶
The following code will generate error P4077:
PROGRAM main
VAR
limits : ARRAY[1..3] OF DINT := [10, 20, 30, 40];
END_VAR
END_PROGRAM
The array has three elements, but the initializer gives four values.
To fix this error, give at most one value for each element, or declare an array large enough to hold every value:
PROGRAM main
VAR
limits : ARRAY[1..4] OF DINT := [10, 20, 30, 40];
END_VAR
END_PROGRAM
The same applies to the default of an array type, and to an array field of a structure, whether its default is declared in the structure or set by a structure initializer.
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.