SA0018: Unusual bit access

Function

Determines bit access to signed variables. However, the IEC 61131-3 standard only permits bit access to bit fields. See also strict rule SA0148: Unusual bit access - strict.

Reason

Signed data types should not be used as bit fields and vice versa. The IEC 61131-3 standard does not provide for such access. This rule must be observed if the code is to be portable.

Exception

Exception for flag enumerations: If an enumeration is declared as flag via the pragma attribute {attribute 'flags'}, the error SA0018 is not issued for bit access with OR, AND or NOT operations.

Importance

Medium

Samples:

PROGRAM MAIN 
VAR
    nINT    : INT;
    nDINT   : DINT;
    nULINT  : ULINT;
    nSINT   : SINT;
    nUSINT  : USINT;
    nBYTE   : BYTE;
END_VAR
nINT.3    := TRUE;               // => SA0018
nDINT.4   := TRUE;               // => SA0018
nULINT.18 := FALSE;              // no error because this is an unsigned data type
nSINT.2   := FALSE;              // => SA0018
nUSINT.3  := TRUE;               // no error because this is an unsigned data type
nBYTE.5   := FALSE;              // no error because BYTE is a bit field