C6317
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 C6317: incorrect operator: logical-not (!) is not interchangeable with ones-complement (~)
This warning indicates that a logical-not (!
) is being applied to a constant that is likely to be a bit-flag. The result of logical-not is Boolean; it is incorrect to apply the bitwise-and (&
) operator to a Boolean value. Use the ones-complement (~
) operator to flip flags.
Example
The following code generates this warning:
#define FLAGS 0x4004
void f(int i)
{
if (i & !FLAGS) // warning
{
// code
}
}
To correct this warning, use the following code:
#define FLAGS 0x4004
void f(int i)
{
if (i & ~FLAGS)
{
// code
}
}
See Also
Bitwise AND Operator: &
Logical Negation Operator: !
One's Complement Operator: ~