beckhoff TE1200 — 4.2.1.3.15 SA0058: Operations of enumeration variables

Configuration | Rules PROGRAM MAIN VAR fREAL : REAL; nDINT : DINT; nLINT : LINT; END_VAR nDINT := nDINT + DINT#11; fREAL := DINT_TO_REAL(nDINT / DINT#3); // => SA0057 fREAL := DINT_TO_REAL(nDINT) / 3.0; // no error fREAL := DINT_TO_REAL(nDINT) / REAL#3.0; // no error nLINT := nLINT + LINT#13; fREAL := LINT_TO_REAL(nLINT / LINT#7); // => SA0057 fREAL := LINT_TO_REAL(nLINT) / 7.0; // no error fREAL := LINT_TO_REAL(nLINT) / REAL#7.0; // no error 4.2.1.3.15 SA0058: Operations of enumeration variables | SA0058: Operations of enumeration variables Sample 1: Enumeration E_Color: TYPE E_Color : ( eRed := 1, eBlue := 2, eGreen := 3 ); END_TYPE MAIN program: PROGRAM MAIN VAR nVar : INT; eColor :

E_Color; END_VAR eColor := E_Color.eGreen; // no error eColor := E_Color.eGreen + 1; // => SA0058 nVar := E_Color.eBlue / 2; // => SA0058 nVar := E_Color.eGreen + E_Color.eRed; // => SA0058 Sample 2: Enumeration E_State with attribute 'flags': {attribute 'flags'} TYPE E_State : ( eUnknown := 16#00000001, eStopped := 16#00000002, eRunning := 16#00000004 ) DWORD; END_TYPE MAIN program: PROGRAM MAIN VAR nFlags : DWORD; nState : DWORD; END_VAR TE1200 46 Version: 2.11.1 Function Determines operations on variables of type enumeration. Assignments are permitted. Reason Enumerations should not be used as normal integer values.

Alternatively, an alias data type can be defined or a subrange type can be used. Exception If an enumeration is marked with the attribute {attribute 'strict'}, the compiler reports such an operation. If an enumeration is declared as a flag via the pragma attribute {attribute 'flags'}, no SA0058 error is issued for operations with AND, OR, NOT, XOR. Importance Medium