Pointer data type

A pointer data type is an extension of EN 61131 (it is not defined there). The reason is safety of programming: Wrong usage of pointer may result in collapsing of the program, which is unacceptable for technology control. This type of error can not be detected neither at the compilation, nor at the runtime. On the other hand, pointers bring benefits like higher efficiency programming, and solving tasks which could not be solved by any other means.

A pointer “points” at a variable which may be of elementary or derived type. In other words, a pointer contains the address of a variable. There are two types of operations which can be done with a pointer: Either its value can be changed (decreased / increased) which changes the variable the pointer is pointing at, or the value of the pointed variable can be processed. The former operation is called pointer arithmetics, tha latter is pointer dereference.

Example

VAR
    MyPtr : PTR_TO INT;
    MyVar : INT;
END_VAR
 
MyVar := 100;
MyPtr := ADR(MyVar); //setting of the pointer to a variable
MyPtr^ := 200;        //variable value has been set to 200