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.

P2034

Code

P2034

Message

NULL can only be assigned to a REF_TO type

This error occurs when NULL is assigned to a variable that is not a REF_TO type. NULL represents an empty reference and can only be used with reference types.

Example

The following code will generate error P2034:

PROGRAM Main
    VAR
        x : INT;
    END_VAR

    x := NULL;  (* Error: NULL can only be assigned to REF_TO types *)
END_PROGRAM

To fix this error, ensure the target variable is a reference type:

PROGRAM Main
    VAR
        x : REF_TO INT;
    END_VAR

    x := NULL;  (* Correct: x is REF_TO INT *)
END_PROGRAM