Microsoft KB Archive/815772

= INFO: C4312 Compiler Warning (Level 1) =

Article ID: 815772

Article Last Modified on 1/11/2007

-

APPLIES TO


 * Microsoft .NET Framework 1.0
 * Microsoft .NET Framework 1.1
 * Microsoft Visual C++ .NET 2002 Standard Edition
 * Microsoft Visual C++ .NET 2003 Standard Edition

-



SUMMARY
When you try to assign a 32-bit value to a 64-bit integer, you receive the following C4312 compiler warning message:

' ': conversion from ' ' to ' ' of greater size

For example, you receive this warning message when you type cast a 32-bit int or 32-bit long to a 64-bit pointer.



MORE INFORMATION
You receive the warning message that is described in the &quot;Symptoms&quot; section when you type cast conversion from an unsigned int to any 64-bit pointer (int* or char*). For example, you receive the warning if you try to assign -1 as shown in following code.

Note 0xFFFFFFFF is equal to -1 for 32-bit targets, but this is not true when you compile for 64-bit. int* ptr; ptr = (int*)0xFFFFFFFF; To avoid this warning, change the code for the 64-bit versions to the following: 0xFFFFFFFFFFFFFFFF

The code appears as follows: int* ptr; ptr = (int*)0xFFFFFFFFFFFFFFFF; Note To receive this warning message, use the /Wp64 compiler switch to verify 64-bit portability issues.

