Partilhar via


C6286

Note

This article applies to Visual Studio 2015. If you're looking for the latest Visual Studio documentation, see Visual Studio documentation. We recommend upgrading to the latest version of Visual Studio. Download it here

warning C6286: (<non-zero constant> || <expression>) is always a non-zero constant. <expression> is never evaluated and may have side effects

This warning indicates that a non-zero constant was detected on the left side of a logical-or operation that occurs in a test context. The resulting expression always evaluates to TRUE. In addition, the right side of the expression appears to have side effects, and they will be lost.

This warning indicates that you may want to examine the right side of the expression carefully to ensure that any side effects needed for proper functionality are not lost.

The (!0 || <expression>) construction is commonly used to force execution of a controlled block.

Example

The following code generates this warning:

#include <stdlib.h>  
#include <stdio.h>  
#define INPUT_TYPE 1   
  
int test();  
  
void f()  
{  
  if (INPUT_TYPE || test())   
  {  
    puts("INPUT_TYPE == 1, expression not evaluated");  
    // code...  
  }  
  else  
  {  
    puts("INPUT_TYPE == 0. Call to test() returned 0");  
    // code...  
  }  
}  

The following code shows one possible solution by breaking if statement into two separate parts:

#include <stdlib.h>  
#include <stdio.h>  
#define INPUT_TYPE 1   
  
int test();  
  
void f()  
{  
  int i;  
  if (INPUT_TYPE)   
  {  
    i = test();  
    // code...  
  }  
  else  
  {  
    puts("INPUT_TYPE false");  
    // code...  
  }  
}  

See Also

Logical OR Operator: ||