Variable Initialization
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.
Data Type | Initialization |
---|---|
Any number data type |
|
Every pointer |
|
|
|
| The default initialization value of each element |
Structure | If an explicit value has not been defined for the individual elements in the declaration, then the default value of the data type is the initialization value. |
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
First the constants
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.
Global variables before local variables
In compiler version 3.3.2.0 and later, 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 pragma global_init_slot.