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) 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