beckhoff TE1200 — 4.2.1.1.18 SA0018: Unusual bit access

Configuration | Rules 4.2.1.1.17 SA0017: Non-regular assignments to pointer variables | SA0017: Non-regular assignments to pointer variables Sample: PROGRAM MAIN VAR nVar : INT; pInt : POINTER TO INT; nAddress : XWORD; END_VAR nAddress := nAddress + 1; pInt := ADR(nVar); // no error pInt := 0; // no error pInt := nAddress; // => SA0017 4.2.1.1.18 SA0018: Unusual bit access | SA0018: Unusual bit access 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 TE1200 28 Version: 2.11.1 Function Determines assignments to pointers, which are not an address (ADR operator, pointer variables) or constant 0. Reason If a pointer is assigned a value that is not a valid address, dereferencing the pointer leads to an “Access Violation Exception”. Importance High 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 [} 70]. 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