Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Compiler Warning (level 1) C4311
Collapse the table of content
Expand the table of content

Compiler Warning (level 1) C4311

'variable' : pointer truncation from 'type' to 'type'

This warning detects 64-bit pointer truncation issues. For example, if code is compiled for a 64-bit architecture, the value of a pointer (64 bits) will be truncated if it is assigned to an int (32 bits). For more information, see Rules for Using Pointers.

For additional information about common causes of warning C4311, see Common Compiler Errors.

The following code example generates C4311 when compiled for a 64-bit target, and then demonstrates how to fix it:

// C4311.cpp
// compile by using: cl /W1 C4311.cpp
int main() {
   void* p = &p;
   unsigned int i = (unsigned int) p;   // C4311 for 64-bit targets
   unsigned long long j = (unsigned long long) p;   // OK
}
Show:
© 2015 Microsoft