Configuration | Rules If this message is enabled, a large number of rather unproblematic situations in the code will be reported. Although a problem can only arise if the operation produces an overflow or underflow in the data type, the Static Analysis cannot differentiate between the individual situations. If you include an explicit typecast in all reported situations, the code will be much slower and less readable! Sample: PROGRAM MAIN VAR nBYTE : BYTE; nDINT : DINT; nLINT : LINT; bResult :
BOOL; END_VAR // ==================================================================================================== = // type size smaller than register size // use of temporary result + implicit casting => SA0066 bResult := ((nBYTE - 1) 255); // => SA0066 // correcting this code by explicit cast so that the type size is equal to or bigger than register size bResult := ((BYTE_TO_LINT(nBYTE) - 1) 255); // no error bResult := ((BYTE_TO_LINT(nBYTE) - LINT#1) LINT#255); // no error // ==================================================================================================== = // result depends on solution platform bResult := ((nDINT - 1) 255); // no error on x86 solution platform // => SA0066 on x64 solution platform // correcting this code by explicit cast so that the type size is equal to or bigger than register size bResult := ((DINT_TO_LINT(nDINT) - LINT#1) LINT#255); // no error // ==================================================================================================== = // type size equal to or bigger than register size // use of temporary result and no implicit casting => no error bResult := ((nLINT - 1) 255); // no error // ==================================================================================================== 4.2.1.4.7 SA0072:
Invalid uses of counter variable | SA0072: Invalid uses of counter variable Sample: PROGRAM MAIN VAR_TEMP nIndex : INT; END_VAR VAR aSample : ARRAY[1..10] OF INT; nLocal : INT; END_VAR FOR nIndex := 1 TO 10 BY 1 DO aSample[nIndex] := nIndex; // no error nLocal := nIndex; // no error nIndex := nIndex - 1; // => SA0072 TE1200 51 Version: 2.11.1 Function Determines write access operations to a counter variable within a FOR loop. Reason Manipulating the counter variable in a FOR loop can easily lead to an infinite loop. To prevent the execution of the loop for certain values of the counter variables, use CONTINUE or simply IF. Importance High PLCopen rule L12