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

Rule:  PCA#017Checked automatically with code checker

Synopsis:Don't compare unrelated enumerations
Language:C++
Severity Level:2
Category:Parts of C++ to Avoid


Description:

It is possible to compare old style enumerations with each other. Although there is no use to compare such enumerations, the compiler won't warn about this because enumerations are treated as integers.

Wrong example:

enum Color { red, yellow, blue };
enum Status { OK, NOK };

void m(Color col) {
  if (col == OK) { // compiles fine, but is not intended
    dosomething();
  }
}

Right example:

enum Color { red, yellow, blue };
enum Status { OK, NOK };

void m(Color col) {
  if (col == red) { 
    dosomething();
  }
}