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

Error Message

'operation' : conversion from 'type1' to 'type2' of greater size

This warning detects 64-bit portability issues. You attempted to assign a 32-bit value to a 64-bit type. For example, casting a 32-bit int or 32-bit long to a 64-bit pointer.

This can be an unsafe conversion in some circumstances when sign extension occurs. If a negative number is assigned to a pointer type of a size greater than the int, sign extension will occur and the pointer value will refer to a memory address different from the value of the int.

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

The following code sample generates C4312:

// C4312.cpp
// compile with: /W1 /Wp64 /LD
void* f(int i) {
   return (void*)i;   // C4312

// OK
void* f2(__int64 i) {
   return (void*)i;

Community Additions

© 2015 Microsoft