Attribute 'strict'
The attribute 'strict' results in compile errors occur in the following cases:
- Arithmetic operation with variables of the enumeration type
- Assignment of a constant value, which is not an enumeration value, to a variable of the enumeration type
(although it is recommended to assign only components of an enumeration type to a variable of that enumeration type) - Assigning a non-constant variable – declared with a data type other than the enumeration type – to a variable of the enumeration type.
(If the right-hand side of the assignment is not a constant, then the data types of the right- and left-hand sides must be the same and must therefore match the enumeration type.)
Syntax: {attribute 'strict'}
Insertion location: Line above the TYPE definition
Examples
Enumeration E_Colors:
{attribute 'qualified_only'}
{attribute 'strict'}
TYPE E_Colors :
(
eRed := 0,
eGreen := 1,
eBlue := 2
);
END_TYPEProgram MAIN:
PROGRAM MAIN
VAR CONSTANT
c2 : INT := 2;
END_VAR
VAR
e1, e2 : E_Colors;
nVar : INT;
END_VAR// Regel 1
e1 := e1 + 1; // NOK: Arithmetische Operation nicht erlaubt
// Regel 2
e1 := 2; // OK: Wert 2 ist im Enum definiert
e1 := c2; // OK: Wert 2 ist im Enum definiert
e1 := 3; // NOK: Wert 3 ist nicht im Enum definiert
// Regel 3
e1 := e2; // OK: Datentyp stimmen überein
e1 := nVar; // NOK: Datentypen stimmen nicht überein