Click to See Complete Forum and Search --> : Warning C4312 (64-Bit portability)
philkr
March 7th, 2006, 08:04 AM
In my code I am casting a DWORD to an int* and I get the following warning:
warning C4312: 'type cast' : conversion from 'DWORD' to 'int *' 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.
I am compiling for Win32. Does my program still work on Windows XP 64 Bit Edition, despite the warning?
NMTop40
March 7th, 2006, 09:01 AM
On a 64-bit platform, a 32-bit int (which is what a DWORD is) is not big enough to store a pointer.
Of course this will break a lot of Win32 SDK which relies on it. But then I guess you should be using Win64 SDK...
SuperKoko
March 7th, 2006, 09:31 AM
I am compiling for Win32. Does my program still work on Windows XP 64 Bit Edition, despite the warning?
It works.
Win32 remains binary compatible.
Your program is executed in 32 bits mode of the 64 bits processor.
But, if you want to compile your program to Win64, with a 64 bits compiler, then it will not work.
You can use UINT_PTR instead of DWORD.
UINT_PTR basically is a type whose size is equal to the max of UINT and LPVOID
The MSDN documentation, now uses UINT_PTR in many places where DWORD were specified.
Under Win32, that is the same thing.
Under Win64, sizeof(UINT_PTR)==8, but sizeof(DWORD)==4.
Under Win64, pointers are 64 bits, while DWORD are 32 bits.
philkr
March 7th, 2006, 10:06 AM
Thanks for the replies!
My recap: The warning is of no interest for me, because I am using Win32 SDK, which will also run on 64-bit system, because there is also a 32-bit mode for backward compatibility.
stober
March 7th, 2006, 11:34 AM
If you don't want to see that warning you can disable it with a pargma
#pragma warning(disable: 4312)
you have to put that before any includes.
VladimirF
March 7th, 2006, 11:53 AM
Instead of disabling ALL 4312 warnings (some of them are not related to 64-bit compatibility), you should simply remove /Wp64 switch from your compiler's options
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.