Skip to content

Latest commit

 

History

History
53 lines (40 loc) · 1.19 KB

c6317.md

File metadata and controls

53 lines (40 loc) · 1.19 KB
description title ms.date f1_keywords helpviewer_keywords ms.assetid
Learn more about: Warning C6317
Warning C6317
11/04/2016
C6317
NOTNOTCOMPLEMENT
__WARNING_NOTNOTCOMPLEMENT
C6317
dc771bb8-f596-4514-af0f-4b39658af365

Warning C6317

Incorrect operator: logical-not (!) is not interchangeable with ones-complement (~)

Remarks

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's incorrect to apply the bitwise-and (&) operator to a Boolean value. Use the ones-complement (~) operator to flip flags.

Code analysis name: NOTNOTCOMPLEMENT

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