Pointer

Variable or function block addresses are saved in pointers while a program is running. Pointer declarations have the following syntax:

<Identifier>: POINTER TO <Datatype/Functionblock>; 

A pointer can point to any data type or function block even to user-defined types. The function of the Address Operator ADR is to assign the address of a variable or function block to the pointer.

A pointer can be dereferenced by adding the content operator "^" after the pointer identifier. With the help of the SIZEOF Operator, e.g. a pointer increment can be done.

Pointer 1:

A pointer is counted byte-wise! You can get it counted up like it is usual in the C-Compiler by using the instruction p=p+SIZEOF(p^);.

Notice

Adress transfer

After an Online Change there might be changes concerning the data on certain addresses. Please regard this in case of using pointers on addresses.

Example:

pt:POINTER TO INT; 
var_int1:INT := 5; 
var_int2:INT; 
pt := ADR(var_int1); 
var_int2:= pt^; (* var_int2 is now 5 *)

Example 2 (Pointer increment):

ptByCurrDataOffs : POINTER TO BYTE;
udiAddress       : UDINT;
(*--- pointer increment ---*)
udiAddress := ptByCurrDataOffs;
udiAddress := udiAddress + SIZEOF(ptByCurrDataOffs^);
ptByCurrDataOffs := udiAddress;
(* -- end of pointer increment ---*)