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.
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.
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^;
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;
IEC 61131-3 Third Edition: Table 12.
To learn about other derived data types, for example STRUCT.
To learn about the built-in elementary types for example INT, or TIME.
To learn about other common language elements.
For a list of all Unicode character codes used in IEC 61131-3 code.
For the meaning of terms used in Fernhill SCADA.