SA0147: Unusual shift operation - strict

Function

Determines bit shift operations that are not performed on bit field data types (BYTE, WORD, DWORD, LWORD).

Reason

The IEC 61131-3 standard only allows bit access to bit field data types. However, the TwinCAT 3 compiler also allows bit shift operations with unsigned data types.

Importance

Low

SA0147: Unusual shift operation - strict 1:

See also non-strict rule SA0052: Unusual shift operation.

Samples:

PROGRAM MAIN
VAR
    nBYTE     : BYTE := 16#45;
    nWORD     : WORD := 16#0045;
    nUINT     : UINT;
    nDINT     : DINT;
    nResBYTE  : BYTE;
    nResWORD  : WORD;
    nResUINT  : UINT;
    nResDINT  : DINT;
    nShift    : BYTE := 2;
END_VAR
nResBYTE := SHL(nByte,nShift);   // no error because BYTE is a bit field
nResWORD := SHL(nWORD,nShift);   // no error because WORD is a bit field
nResUINT := SHL(nUINT,nShift);   // => SA0147
nResDINT := SHL(nDINT,nShift);   // => SA0147