Configuration | Rules 4.2.1.3 SA0041 - SA0060 | SA0041 - SA0060 4.2.1.3.1 SA0041: Possibly loop-invariant code | SA0041: Possibly loop-invariant code Sample: In the following sample SA0041 is output as error/warning, since the variables nTest1 and nTest2 are not used in the loop. PROGRAM MAIN VAR CONSTANT cMax : INT := 3; END_VAR VAR nTest1 : INT := 5; nTest2 : INT := nTest1; nTest3 : INT; nTest4 : INT; nTest5 : INT; nTest6 : INT; nIndex : INT; nCounter :
INT; END_VAR FOR nCounter := 1 TO 100 DO nTest3 := nTest1 + nTest2; // => SA0041 nTest4 := nTest3 + nCounter; // no loop-invariant code, because nTest3 and nCounter are used within loop nTest6 := nTest5; // simple assignments are not regarded END_FOR FOR nIndex := 1 TO cMax-1 DO // => SA0041 for "cMax-1" nCounter := nCounter + 1; END_FOR 4.2.1.3.2 SA0042: Usage of different access paths | SA0042: Usage of different access paths Samples: In the following sample SA0042 is output as error/warning, because the global variable nGlobal is accessed directly and via the GVL namespace, and because the function CONCAT is accessed directly and via the library namespace. Global variables:
VAR_GLOBAL nGlobal : INT; END_VAR MAIN program: PROGRAM MAIN VAR sVar : STRING; END_VAR TE1200 39 Version: 2.11.1 Function Determines assignments in (FOR, WHILE, REPEAT) loops that calculate the same value for each loop pass. Such lines of code could be inserted outside the loop. Reason This is a performance warning. Code that is executed in a loop, but does the same thing in every loop pass, can be executed outside the loop. Importance Medium Function Determines the usage of different access paths for the same variable. Reason Different access to the same element reduces the readability and maintainability of a program.
We recommend consistent use of {attribute 'qualified-only'} for libraries, global variable lists and enumerations. This forces fully qualified access. Importance Low