For new code consider using the REF_TO type instead of POINTER TO.
A pointer type declares a variable that takes the address of another variable. For example:
Type pVoltage : POINTER TO INT; End_Type
You can assign the address of a variable using the address operator, commercial at (@) character. For example:
Var V1, V2 : INT; pV : Pointer to INT; End_Var (* Get the address of V2 *) pV := @V2;
The dereference operator, circumflex accent (^) character, is used to dereference the pointer. For example:
(* Take the address of V2 *) pV := @V2; (* Assign the value 12 to V2 via the pointer pV *) pV^ := 12; (* Assign the value of V2 to V1 via the pointer pV *) V1 := pV^;
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 pV <> NULL THEN pV^ := 12; END_IF;
Pointers can be declared constant, which prevents the target of the pointer being written to. For example:
Type pVoltage : POINTER TO CONSTANT INT; End_Type
The compiler will report an error if you try and write a value via a constant pointer. For example:
Type V : INT; pVoltage : POINTER TO CONSTANT INT; End_Type pV := @V; (* Compiler will report an error for this line... *) pV^ := 12;
The POINTER TO type modifier is an extension to the IEC 61131-3 standard.
For IEC 61131-3 pointer declarations use the REF_TO type declaration.
To learn about other derived data types, for example STRUCT.
To learn about declaring pointers that follow the IEC 61131-3 standard.
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.