Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
C6239
Collapse the table of content
Expand the table of content

C6239

warning C6239: (<non-zero constant> && <expression>) always evaluates to the result of <expression>. Did you intend to use the bitwise-and operator?

This warning indicates that a non-zero constant value, other than one, was detected on the left side of a logical-AND operation that occurs in a test context. For example, the expression ( 2 && n ) is reduced to (!!n), which is the Boolean value of n.

This warning typically indicates an attempt to check a bit mask in which the bitwise-AND (&) operator should be used, and is not generated if the non-zero constant evaluates to 1 because of its use for selectively choosing code paths.

The following code generates this warning:

#include <stdio.h>
#define INPUT_TYPE 2
void f( int n )
{
   if(INPUT_TYPE && n) // warning 6239
   {
      puts("boolean value of n is true");
   }
   else
   {
      puts("boolean value of n is false");
   }
}

To correct this warning, use bitwise-AND (&) operator as shown in the following code:

#include <stdio.h>
#define INPUT_TYPE 2
void f( int n )
{
   if( ( INPUT_TYPE & n ) )
   {
      puts("bitmask true");
   }
   else
   {
      puts("bitmask false");
   }
}
Show:
© 2015 Microsoft