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.
V4004¶
- Code
V4004
- Message
Null reference dereference during program execution
The program attempted to dereference a reference variable that is NULL.
A NULL reference does not point to any variable, so dereferencing it with
the ^ operator is not valid.
Example¶
The following code will generate error V4004:
PROGRAM Main
VAR
r : REF_TO INT := NULL;
value : INT;
END_VAR
value := r^; (* Error: r is NULL, cannot dereference *)
END_PROGRAM
The reference r is NULL and does not point to any variable. Dereferencing
it attempts to read a value that does not exist.
To fix this error, ensure the reference points to a valid variable before dereferencing:
PROGRAM Main
VAR
counter : INT;
r : REF_TO INT := REF(counter);
value : INT;
END_VAR
IF r <> NULL THEN
value := r^; (* Correct: r points to counter *)
END_IF;
END_PROGRAM