P4032¶
- Code
P4032
- Message
Constant referenced in type parameter has no initializer
This error occurs when a constant name is used in a type parameter (such as a STRING length or array bound) but the referenced constant does not have an initializer value.
Example¶
The following code will generate error P4032:
VAR_GLOBAL CONSTANT
MAX_LEN : INT;
END_VAR
FUNCTION_BLOCK MyFB
VAR_INPUT
name : STRING[MAX_LEN];
END_VAR
END_FUNCTION_BLOCK
The constant MAX_LEN is declared without a value. To fix this error, provide an initializer:
VAR_GLOBAL CONSTANT
MAX_LEN : INT := 100;
END_VAR
The same fix applies when the constant is used as an array bound.
The declaration below triggers P4032 at the ARRAY declaration
because CAPACITY has no value:
VAR_GLOBAL CONSTANT
CAPACITY : INT; (* No initializer *)
END_VAR
FUNCTION_BLOCK Ring
VAR
slots : ARRAY[1..CAPACITY] OF INT; (* Error: bound has no value *)
END_VAR
END_FUNCTION_BLOCK
Adding := 32 (or any integer literal) to CAPACITY resolves the
error and lets the compiler determine the array’s size.
See Also¶
Initial Values — initializer syntax
STRING —
STRINGlength parameterArray Types — array bound expressions
P4008 —
CONSTANTvariable missing an initializerP4030 — constant referenced in a type parameter is not defined
P4031 — constant referenced in a type parameter is not an integer type
References¶
IEC 61131-3 §2.4.3
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.