Attention
IronPLC can only run very simple programs. The steps described are accurate but many language features are not yet supported.
P4022¶
- Code
P4022
- Message
Variable initializer type is incompatible with declared type
This error occurs when a variable’s initializer value is not compatible with the variable’s declared type. Each type in IEC 61131-3 accepts only specific kinds of literal values.
Example¶
The following code will generate error P4022:
PROGRAM main
VAR
dummy : INT := 10.0; (* Error: real literal cannot initialize integer type *)
END_VAR
END_PROGRAM
The literal 10.0 is a real (floating-point) value, but INT is an integer type.
Real literals can only initialize REAL or LREAL variables.
To fix this error, use a literal that matches the declared type:
PROGRAM main
VAR
dummy : INT := 10;
END_VAR
END_PROGRAM