IEC 61131-3 REF_TO Type

Help Contents

Introduction

A reference is the address of another variable. For example:

Type
    rVoltage : REF_TO INT;
End_Type

The variable rVoltage is a reference to an INT.

Reference Operator REF

You can assign the address of a variable using the REF() operator. For example:

Var
    V1, V2 : INT;
    rV : REF_TO INT;
End_Var

    (* Get the address of V2 *)
    rV := REF( V2 );

The variable rV contains the address of the variable V2.

Dereference Operator (^)

The dereference operator, circumflex accent (^) character, is used to dereference the reference. For example:

(* Take a reference to V2 *)
rV := REF( V2 );

(* Assign the value 12 to V2 via the reference rV *)
rV^ := 12;

(* Assign the value of V2 to V1 via the reference rV *)
V1 := rV^;

NULL Value

The NULL keyword, is used to indicate no address. If a code statement attempts to dereference a pointer with no address, the program will halt with the error "Null pointer dereference". As a defensive coding technique you can test for NULL using an IF Statement:

IF rV <> NULL THEN
    rV^ := 12;
END_IF;

Standards Compliance

IEC 61131-3 Third Edition: Table 12.

Further Information

Derived Data Types

To learn about other derived data types, for example STRUCT.

Elementary Types

To learn about the built-in elementary types for example INT, or TIME.

Common Elements

To learn about other common language elements.

Character Codes

For a list of all Unicode character codes used in IEC 61131-3 code.

Glossary

For the meaning of terms used in Fernhill SCADA.