Skip to main content

SA0012: Variable which could be declared as constants

Detects variables which are not accessed with write permission and therefore could be declared as constants

Justification: If a variable is written only at the declaration point and is otherwise used only for reading, then the static analysis assumes that the variable should also not to be changed. Firstly, a declaration as a constant results in checking that the variable is not changed when the program is changed. Secondly, the declaration as a constant may result in faster code.

Important

If multiple applications exist in one project, then only the objects below the currently active application are affected. If there is only one application, then the objects in the common POU pool are also affected.

Importance: Low

Example 24. Example
PROGRAM PLC_PRG
VAR
        iVar : INT := INT#17;
        iTest : INT;
END_VAR
iTest := iTest + iVar;   // SA0012: 'iVar' could be declared as constant

Output in the Messages view:

  • sa_icon_message.png SA0012: Variable 'iVar' could be declared as constant