Configuration | Rules 4.2.1.1.10 SA0010: Arrays with only one component | SA0010: Arrays with only one component Samples: PROGRAM MAIN VAR aEmpty1 : ARRAY [0..0] OF INT; // => SA0010 aEmpty2 : ARRAY [15..15] OF REAL; // => SA0010 END_VAR 4.2.1.1.11 SA0011: Useless declarations with only one component | SA0011: Useless declarations with only one component Sample 1 – Structure: TYPE ST_SingleStruct : // => SA0011 STRUCT nPart : INT; END_STRUCT END_TYPE Sample 2 – Union: TYPE U_SingleUnion : // => SA0011 UNION fVar : LREAL; END_UNION END_TYPE Sample 3 – Enumeration: TYPE E_SingleEnum : // => SA0011 ( eOnlyOne := 1 ); END_TYPE 4.2.1.1.12 SA0012:
Variables which could be declared as constants | SA0012: Variables which could be declared as constants Sample: TE1200 25 Version: 2.11.1 Function Determines arrays containing only a single component. Reason An array with a component can be replaced by a Base Type variable. Access to such a variable is much faster than access to a variable via an index. Exception The length of an array is often determined by a constant and used as a parameter for a program. The program can then work with arrays of different lengths and does not have to be changed if the length is only 1. Such a situation should be documented accordingly.
Importance Low Function Determines structures, unions, or enumerations with only one component. Reason No structures, unions or enumerations with only one component should be declared. Such declarations can be confusing for readers. A structure with only one element can be replaced by an alias type. An enumeration with an element can be replaced by a constant. Importance Low PLCopen rule CP22/CP24 Function Determines variables that are not subject to write access and therefore could not be declared as constants. Reason If a variable is only written at the declaration point and is otherwise only used in read mode, the static analysis assumes that the variable is to remain unchanged.
Declaration as a constant means that the variable is checked for changes in the event of program modifications. Plus, declaration as a constant may lead to faster code. Importance Low