E0022: an address where the standard does not allow one
A FUNCTION has no located variables: it keeps nothing between calls (Ed.2 Table E.1).
AT %I*, AT %Q* and AT %M* leave the address for the configuration
to give in VAR_CONFIG (Ed.3 6.5.5.4). VAR_CONFIG reaches a variable by
its name, through the program instance and the function block instances
it sits in, so the * is allowed only where that path exists:
- in
VARof a PROGRAM or FUNCTION_BLOCK, under a name (Ed.3 Annex A,Loc_Partly_Var_Decl; CODESYS documents the same); - in a field of a structure type (Ed.3 6.4.4.8), when the structure is declared there.
Not in VAR_OUTPUT, VAR_INPUT, VAR_IN_OUT, VAR_TEMP or
VAR_EXTERNAL, not in a
global (a global has one instance: write its address in full), not inside
an array (a path names no element), and not in a body: a body uses the
variable’s name.
Inside a PROGRAM or FUNCTION_BLOCK, one VAR block holds one kind of
declaration: plain variables, variables located in full, or *
addresses. The grammar gives each its own block (Ed.3 Annex A
Var_Decls, Loc_Var_Decls, Loc_Partly_Var_Decl; Ed.2 B.1.4.3 the
same), and matiec refuses a mix too. CODESYS accepts one; split it into
two blocks and every compiler reads it:
PROGRAM main
VAR
count : INT;
lamp AT %QX0.0 : BOOL; (* E0022: a located variable among plain ones *)
END_VAR
END_PROGRAM
The * takes the place of the size and the numbers both: %I*, not
%IX* (that is E0004).
FUNCTION_BLOCK valve
VAR_OUTPUT open AT %I* : BOOL; END_VAR (* E0022: not in VAR_OUTPUT *)
VAR coil AT %Q* : BOOL; END_VAR (* fine *)
END_FUNCTION_BLOCK
Only a BOOL starts at a bit; an array, structure or string, and any wider variable, starts at a byte: its address is where it starts, and it takes its own type’s size from there (Ed.3 6.5.5.3; W0004 when the size prefix is not that size).
n AT %MX0.3 : INT; (* E0022 *)
n AT %MW0 : INT; (* fixed *)
A function block instance has no address (an interface there is E0031): AT takes an elementary type, an array, a structure or a string (Ed.3 6.5.5, Loc_Var_Spec_Init).
t AT %MW0 : TON; (* E0022 *)