Detects shift operations (bit shift) on signed variables. In the case of shift operations
on bitfield data types (Byte
, DWORD
, LWORD
, WORD
), an error is not reported.
Justification: CODESYS permits shift operations on signed data types. However, these operations are unusual and can be confusing. The IEC 61131-3 standard does not provide for these kinds of operations. Therefore, they should be avoided in order to increase the portability of the code to other development systems.
Importance: Medium
Example
PROGRAM PLC_PRG VAR iTemp : INT; dwTemp1 : DWORD; byTemp2 : BYTE; diTemp3 : DINT; siTemp4 : SINT; liTemp5 : LINT; END_VAR //the following lines each will cause an SA0052: iTemp := SHL(iTemp, BYTE#2); diTemp3 := SHR(diTemp3, BYTE#4); siTemp4 := ROL(siTemp4, BYTE#2); liTemp5 := ROR(liTemp5, BYTE#2); //no error SA0052 because DWORD and BYTE are bit field data types: dwTemp1 := SHL(dwTemp1, BYTE#3); byTemp2 := SHR(byTemp2, BYTE#1); ---> SA0052: Unusual shift operation