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
Expand Minimize
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.

Compiler Warning (level 1) C4319

Error Message

'operator' : zero extending 'type' to 'type' of greater size

The result of the ~ operator is unsigned and then converted to a larger type.

In the following example, ~(a - 1) is evaluated as a 32-bit unsigned long expression and then converted to 64 bits by zero extension. This leads to pointer truncations.

// C4319.cpp
// compile with: /W1 /Wp64 /Tc
void* p;
unsigned long a;
typedef unsigned __int64 ULONG_PTR;

int main() {
  p = (void*)((ULONG_PTR)p & ~(a - 1)); // C4319 expected

Community Additions

© 2015 Microsoft