P4064¶
- Code
P4064
- Message
Variable declared CONSTANT is written
This error occurs when a statement writes a variable declared CONSTANT.
A constant holds its initial value for the whole run, so it cannot be the
target of an assignment, the control variable of a FOR loop, the target
of an output binding (=>), or an argument bound to a VAR_IN_OUT
parameter.
The same applies to a global written through a VAR_EXTERNAL CONSTANT
declaration. A write through a plain VAR_EXTERNAL is checked against that
declaration only, so it is not affected by another program that declares the
same global VAR_EXTERNAL CONSTANT.
Example¶
The following code will generate error P4064:
PROGRAM main
VAR CONSTANT
Limit : INT := 10;
END_VAR
Limit := 20; (* Error: Limit is a constant *)
END_PROGRAM
To fix this error, remove the write, or declare the variable without
CONSTANT if the program needs to change it:
PROGRAM main
VAR
Limit : INT := 10;
END_VAR
Limit := 20;
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.