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

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;
© 2016 Microsoft