Attention
IronPLC implements many parts of the IEC 61131-3 standard and is working toward full Structured Text support. Key features still missing include arrays and structures. Try it out in the IronPLC Playground.
P2033¶
- Code
P2033
- Message
Arithmetic operations are not allowed on reference types
This error occurs when arithmetic operations (+, -, *, /, MOD) are performed on reference types. Pointer arithmetic is not allowed in IEC 61131-3.
Example¶
The following code will generate error P2033:
PROGRAM Main
VAR
x : INT;
xRef : REF_TO INT := REF(x);
END_VAR
xRef := xRef + 1; (* Error: arithmetic on references is not allowed *)
END_PROGRAM
To fix this error, dereference the variable first, then perform arithmetic on the value:
PROGRAM Main
VAR
x : INT;
xRef : REF_TO INT := REF(x);
y : INT;
END_VAR
y := xRef^ + 1; (* Correct: dereference first, then add *)
END_PROGRAM