Compiler Warning (level 1) C4311
TOC
Collapse the table of content
Expand the table of content
The document is archived and information here might be outdated

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
}
Show:
© 2016 Microsoft