Retain variables are declared by the keyword RETAIN
is added in programming objects in the scope VAR
, VAR_INPUT
, VAR_OUTPUT
, VAR_IN_OUT
, VAR_STAT
, or VAR_GLOBAL
.
Syntax for the declaration
<scope> RETAIN <identifier>: <data type> ( := <initialization> )? // ( ... )? : Optional END_VAR <scope> : VAR | VAR_INPUT | VAR_OUTPUT | VAR_IN_OUT | VAR_STAT | VAR_GLOBAL
An assignment of inputs, outputs, or memory addresses with the AT
keyword is not permitted.
Example
In a POU
VAR RETAIN iVarRetain: INT; END_VAR
In a GVL
VAR_GLOBAL RETAIN g_iVarRetain: INT; END_VAR
-
Possible declaration locations