P2036¶
- Code
P2036
- Message
Nested REFERENCE TO (a reference to a reference) is not supported
This error occurs when a TwinCAT REFERENCE TO is nested: a REFERENCE TO
whose target is a reference or pointer type, or a reference of any kind whose
target is spelled REFERENCE TO. TwinCAT declares neither REFERENCE TO
REFERENCE nor POINTER TO REFERENCE. IronPLC gives a REFERENCE TO
variable its automatic dereference by its own declaration, which a reference
reached through another reference does not have, and which does not reach
through a pointer the variable refers to, so a REFERENCE TO a pointer is
not supported either.
The IEC 61131-3 REF_TO and the CODESYS POINTER TO nest:
REF_TO REF_TO INT and POINTER TO POINTER TO INT are references to a
reference, followed one level at a time with ^. See
Nested references on the reference types page.
Example¶
The following code will generate error P2036:
TYPE
IntRef : REF_TO INT;
END_TYPE
PROGRAM Main
VAR
rr : REFERENCE TO IntRef; (* Error: REFERENCE TO a reference *)
pp : POINTER TO REFERENCE TO INT; (* Error: a reference to a REFERENCE TO *)
END_VAR
END_PROGRAM
To fix this error, refer to the reference with REF_TO or POINTER TO,
which nest, or to the value itself with REFERENCE TO:
TYPE
IntRef : REF_TO INT;
END_TYPE
PROGRAM Main
VAR
x : INT;
rr : REF_TO IntRef; (* Correct: a reference to a reference *)
r : REFERENCE TO INT; (* Correct: a reference to a value *)
END_VAR
r REF= x;
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.