Skip to main content

SA0052: Unusual shift operation

Detects shift operations (bit shift) on signed variables. In the case of shift operations on bit field 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 62. 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 bitfield datatypes:
dwTemp1 := SHL(dwTemp1, BYTE#3);
byTemp2 := SHR(byTemp2, BYTE#1);

Output in the Messages view:

  • sa_icon_message.png SA0052: Unusual shift operation