SA0147: Unusual shift operation - strictPermalink

Detects bit shift operations that are not made to bitfield data types (‎BYTE‎, ‎WORD‎, ‎DWORD‎, ‎LWORD‎)

Justification: The IEC 61131-3 standard permits bit access only to bitfield data types. However, the CODESYS compiler also permits bit shift operations with unsigned data types.

Importance: Low

See also the strict rule SA0018.

Example

PROGRAM PLC_PRG
VAR
  in_byte : BYTE := 16#45;   // 2#01000101
  in_word : WORD := 16#0045; // 2#0000000001000101
  in_uint : UINT;
  in_dint : DINT;
  erg_byte : BYTE;
  erg_word : WORD;
  erg_uint : UINT;
  erg_dint : DINT;
  n: BYTE := 2;
END_VAR

erg_byte := SHL(in_byte,n);  // no error because BYTE is a bit field
erg_word := SHL(in_word,n);  // no error because WORD is a bit field
erg_uint := SHL(in_uint,n);  // SA0147
erg_dint := SHL(in_dint,n);  // SA0147

--> SA0147: Unusual shift operation - strict