Skip to main content

SA0034: Enumerations with incorrect assignment

Detects values which are assigned to an enumeration variable. Only defined enumeration constants of an enumeration variable are permitted to be assigned.

Justification: A variable of the enumeration type should have only the intended values, otherwise the code that uses this variable may not work correctly. We recommend to always use enumerations with the pragma {attribute 'strict'}. Then the compiler already checks the correct use of the enumeration components.

Importance: High

Example 46. Example
TYPE COLOR :
(
        Red := 0,
        Green,
        Yellow
);
END_TYPE
PROGRAM PLC_PRG
VAR
    eColor1: COLOR;
END_VAR
eColor1 := COLOR.Red;
eColor1 := 1;    // SA0034

Output in the Messages view:

  • sa_icon_message.png SA0034: Use enumeration value instead of 'INT#1'



For more information, see: