Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here.

C6286

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

Community Additions

ADD
Show:
© 2015 Microsoft