P4037¶
- Code
P4037
- Message
Constant expression in VAR initializer requires –allow-constant-initializer-expressions flag
This error occurs when a VAR initializer uses a constant expression
(arithmetic between literals and/or references to declared CONSTANT
variables) instead of a bare literal, without the
--allow-constant-initializer-expressions compiler flag. The IEC 61131-3
standard’s initializer grammar only permits a single literal in this
position. Constant expressions are a vendor extension.
Example¶
The following code will generate error P4037:
VAR_GLOBAL CONSTANT
PI : LREAL := 3.14159265358979;
END_VAR
PROGRAM main
VAR
d2r : LREAL := PI/180.0;
END_VAR
END_PROGRAM
To fix this error, either use a literal value directly:
PROGRAM main
VAR
d2r : LREAL := 0.017453292519943295;
END_VAR
END_PROGRAM
Or enable the vendor extension:
Pass the --allow-constant-initializer-expressions flag to enable it, or select a dialect that includes it. See
Enabling Dialects and Features for the dialects and flags
reference.
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.