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

Error Message

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

This warning detects 64-bit portability issues. For example, if code is compiled on a 64-bit platform, the value of a pointer (64 bits) will be truncated if it is assigned to an int (32 bits).

This warning is only issued when /Wp64 is used. See /Wp64 for more information. Also, see Rules for Using Pointers.

For additional information on C4311, see Common Compiler Errors.

The following code sample generates C4311:

// C4311.cpp
// compile with: /W1 /Wp64
#include <stddef.h>
int main() {
   void* p = &p;
   unsigned long i = (unsigned long)p;   // C4311
   intptr_t j = (intptr_t)p;   // OK

Community Additions

© 2015 Microsoft