SA0052: Unusual shift operation
Function | Determines shift operation (bit shift) on signed variables. However, the IEC 61131-3 standard only permits shift operations to bit fields. See also strict rule SA0147: Unusual shift operation - strict. |
Reason | TwinCAT allows shift operations on signed data types. However, such operations are unusual and can be confusing. The IEC-61131-3 standard does not provide for such operations, so you should avoid them. |
Exception | Shift operation on bit field data types (byte, DWORD, LWORD, WORD) do not result in a SA0052 error. |
Importance | Medium |
Samples:
PROGRAM MAIN
VAR
nINT : INT;
nDINT : DINT;
nULINT : ULINT;
nSINT : SINT;
nUSINT : USINT;
nLINT : LINT;
nDWORD : DWORD;
nBYTE : BYTE;
END_VARnINT := SHL(nINT, BYTE#2); // => SA0052
nDINT := SHR(nDINT, BYTE#4); // => SA0052
nULINT := ROL(nULINT, BYTE#1); // no error because this is an unsigned data type
nSINT := ROL(nSINT, BYTE#2); // => SA0052
nUSINT := ROR(nUSINT, BYTE#3); // no error because this is an unsigned data type
nLINT := ROR(nLINT, BYTE#2); // => SA0052
nDWORD := SHL(nDWORD, BYTE#3); // no error because DWORD is a bit field data type
nBYTE := SHR(nBYTE, BYTE#1); // no error because BYTE is a bit field data type