INFO: C4312 Compiler Warning (Level 1) (815772)



The information in this article applies to:

  • Microsoft .NET Framework 1.0
  • Microsoft .NET Framework 1.1
  • Microsoft Visual C++ .NET (2002)
  • Microsoft Visual C++ .NET (2003)

SUMMARY

When you try to assign a 32-bit value to a 64-bit integer, you receive the following C4312 compiler warning message:
'variable': conversion from 'type' to 'type' 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 "Symptoms" 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.

REFERENCES

For more information, see the following Microsoft Developer Network (MSDN) Web sites:

Beyond Windows XP: Get Ready Now for the Upcoming 64-Bit Version of Windows
http://msdn.microsoft.com/msdnmag/issues/01/11/xp64/default.aspx


Modification Type:MinorLast Reviewed:6/19/2003
Keywords:kbCompiler kbinfo KB815772 kbAudDeveloper