4.4.3.4 Variable declarations
Of the variable types and attributes defined in IEC 61131-3 the following are suitable for creating safety-ori-
ented applications:
Keyword Description Suitable (Yes / To a limited extent /
No) (comment)
VAR Local block variable Yes
VAR_INPUT Block input parameter Yes
VAR_OUTPUT Block output parameter Yes
VAR_IN_OUT Block reference parameter To a limited extent (To illustrate the
side effect the parameter should be
identified with a prefix. Even better
would be to use an input and output
parameter instead.)
VAR_GLOBAL Global variable Yes (We strongly recommend identi-
fying global variables with a prefix
such as "G_" or "GS_" (for safety-ori-
ented variables).)
VAR_EXTERNAL Declaration of global variables used in
the block
Yes/optional (not required in CoD-
eSys)
AT Variable address allocation Yes (see next chapter)
CONSTANT Declaration as constant (no write
access possible)
Yes (We recommend to declare each
constant explicitly.)
RETAIN Variable value is preserved after switch-
off
No, not supported
PERSISTENT Variable value is preserved after
reloading
No, not supported
In the interest of better readability the following rules should be followed for the declaration of variables:
n Only one block of declaration type (e.g., VAR, VAR_INPUT, VAR_OUTPUT, VAR_IN_OUT,
VAR_GLOBAL and combindations with CONSTANT) per component
n Only one variable declaration per line with informative comment
Bad:
VAR
A, B, C: BOOL; (* several variables *)
END_VAR
Good:
VAR
A: BOOL; (* first variable *)
B: BOOL; (* second variable *)
C: BOOL; (* third variable *)
END_VAR
n Local variables (VAR) should always have a different name. Obscuring of global variables through local
variables must be avoided.
Configuration and programming
CoDeSys Safety programming guidelines > Language-specific programming guidelines
30.03.2017 AC500-S 213