C6326

 

For the latest documentation on Visual Studio 2017 RC, see Visual Studio 2017 RC Documentation.

warning C6326: potential comparison of a constant with another constant

This warning indicates a potential comparison of a constant with another constant, which is redundant code. You must check to make sure that your intent is properly captured in the code. In some cases, you can simplify the test condition to achieve the same result.

The following code generates this warning because two constants are compared:

#define LEVEL    
const int STD_LEVEL = 5;  
  
const int value =   
#ifdef LEVEL  
10;  
#else   
5;  
#endif  
  
void f()  
{  
  if( value > STD_LEVEL)  
  {  
    // code...  
  }  
  else  
  {  
    // code...  
  }  
}  

The following code shows one method of correcting this warning by using the #ifdef statements to determine which code should execute:

#define LEVEL    
const int STD_LEVEL = 5;  
  
const int value =   
#ifdef LEVEL  
10;  
#else   
5;  
#endif  
  
void f ()  
{  
#ifdef LEVEL  
  {  
    // code...  
  }  
#else  
  {  
    // code...  
  }  
#endif  
}   

Show: