beckhoff TE1200 — 4.2.1.4.11 SA0077: Enumeration type mismatch with CASE expression

Configuration | Rules 4.2.1.4.10 SA0076: Missing enumeration constant | SA0076: Missing enumeration constant Sample: In the following sample the enumeration value eYellow is not treated as a CASE branch. Enumeration E_Color: TYPE E_Color : ( eRed, eGreen, eBlue, eYellow ); END_TYPE MAIN program: PROGRAM MAIN VAR eColor : E_Color; bVar : BOOL; END_VAR eColor := E_Color.eYellow; CASE eColor OF // => SA0076 E_Color.eRed: bVar := FALSE; E_Color.eGreen, E_Color.eBlue: bVar := TRUE; ELSE bVar := NOT bVar; END_CASE 4.2.1.4.11 SA0077: Enumeration type mismatch with CASE expression | SA0077: Enumeration type mismatch with CASE expression Sample: Enumeration E_Sample: TYPE E_Sample :

( eNull, eOne, eTwo ) DWORD; END_TYPE MAIN program: TE1200 53 Version: 2.11.1 Function Determines whether each enumeration constant is used as a condition in CASE statements and queried in a CASE branch. Reason Defensive programming requires the processing of all possible values of an enumeration. If no action is required for a particular enumeration value, you should indicate this explicitly with a comment. This makes it clear that the value was not simply overlooked. Importance Low Function Detects code positions where a CASE statement mixes enumeration values with non- enumeration types.

Reason Mixing enumeration values and integer values in CASE constructs violates data type security, reduces the readability of the code and impairs maintainability. Enumeration values ensure semantic clarity. Using raw integer values carries the risk of subtle errors and makes the code more difficult to understand. Data type changes to enumerations can also destroy integer-based branches without being noticed. Importance Low