The standard initialization value for all declarations is 0
. In the declaration part you can also specify user-defined initialization values
for each variable and each data type.
The user-defined initialization starts with the assignment operator :=
and consists of any valid expression of the programming language ST (structured text).
You thus define the initialization value with the help of constants, other variables
or functions. If you use a variable, you must also initialize it.
Examples
VAR var1:INT := 12; // initialization value 12 x : INT := 13 + 8; // initalization value defined by an expression of constants y : INT := x + fun(4); // initialization value defined by an expression, // that contains a function call; notice the order! z : POINTER TO INT := ADR(y); // not described in the standard IEC61131-3: // initialization value defined by an adress function; // Notice: In this case the pointer will not be initialized // during an Online Change *) END_VAR
Notes on the order of initialization
From compiler version 3.5.3.40, variables in a function block are initialized in the following order: firstly, all constants in accordance with the order of their declarations, then all other variables in accordance with the order of their declarations.




NOTICE

From compiler version 3.3.2.0, variables from global variable lists are always initialized before the local variables of a POU.
For more information, see: ⮫ Declaration and initialization of structure variables and ⮫ “Attribute: global_init_slot ”.