Detects operations on variables of the enumeration data type Assignments are permitted.
Justification: Enumerations should not be used as ordinary integer values. You can also define an alias data type or use a subrange type.
Importance: Medium
Exception: If an enumeration is tagged with the pragma {attribute 'strict'}, then the compiler already reports this kind of operation.
If an enumeration is declared as a flag by the pragma {attribute 'flags'}, then an error is not issued for AND, OR, NOT, or oder XOR operations.
Example
TYPE My_Enum : ( red := 1, blue := 2, green := 3, black := 4 ); END_TYPE PROGRAM PLC_PRG VAR iTemp1 : INT; abc : My_Enum; END_VAR iTemp1 := iTemp1 + INT#1; abc := My_Enum.red; // OK iTemp1 := My_Enum.black / My_Enum.blue; // SA0058 iTemp1 := My_Enum.green / My_Enum.red; // SA0058 --> SA0058: Operations on enumeration variables
Example with a pragma {attribute 'flags'}
{attribute 'flags'} // declaring the enumeration as a "flag"
TYPE Flags :
(
Unknown := 16#00000001,
Stopped := 16#00000002,
Running := 16#00000004
) DWORD;
END_TYPE
PROGRAM PLC_PRG
VAR
iTemp1 : INT;
abc : Flags;
batate : BYTE;
dwFlags : DWORD;
dwState : DWORD;
END_VAR
// OK for the following
IF (dwFlags AND Flags.Unknown) <> DWORD#0 THEN
dwState := dwState AND Flags.Unknown;
ELSIF (dwFlags OR Flags.Stopped) <>DWORD#0 THEN
dwState := dwState OR Flags.Running;
END_IF