IEC 61131-3 Pointer Type

Help Contents

Introduction

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

Address Operator (@)

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;

Dereference Operator (^)

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^;

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 pV <> NULL THEN
    pV^ := 12;
END_IF;

Constant Pointers

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;

Standards Compliance

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.

Further Information

Derived Data Types

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

REF_TO data type

To learn about declaring pointers that follow the IEC 61131-3 standard.

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.