SA0147: Unusual shift operation – strict
Detects bit shift operations which are not made to bit field data types (BYTE, WORD, DWORD, LWORD)
Justification: The IEC 61131-3 standard permits bit access only to bit field data types. However, the CODESYS compiler also permits bit shift operations with unsigned data types.
Importance: Low
Tip
See also the strict rule SA0018.
Example 108. 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
Output in the Messages view:
SA0147: Unusual shift operation – strict