TICS Coding Standard Viewer 
TIOBE Software Quality Framework
Print-friendly version
©TIOBE Software www.tiobe.com
 
C++ Coding Standard
Search

Rule:  PCA#002Checked automatically with code checker

Synopsis:Do not assume that an enumerator has a specific value
Language:C++
Severity Level:4
Category:Parts of C++ to Avoid


Description:

A common pitfall is that it is assumed that the enumerators of an enumeration run from 0 to (max - 1). Although each enumerator has an integer value, no code may be written that relies on the integer value of the enumerator. It is only allowed to use the assignment operator = and the comparison operators == and !=. Furthermore, enumerators can be used in a switch statement.

An exception to this rule is when an enum is used as an alternative to define a constant numeric value as follows:

enum { MAX_BUFFER_LENGTH = 1000 };

This mechanism makes it possible to define and use a constant numeric value directly in a class definition.