Warning C4312 (64-Bit portability)
In my code I am casting a DWORD to an int* and I get the following warning:
Code:
warning C4312: 'type cast' : conversion from 'DWORD' to 'int *' of greater size
Quote:
Originally Posted by MSDN
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?
Re: Warning C4312 (64-Bit portability)
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...
Re: Warning C4312 (64-Bit portability)
Quote:
Originally Posted by phillkr
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.
Re: Warning C4312 (64-Bit portability)
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.
Re: Warning C4312 (64-Bit portability)
If you don't want to see that warning you can disable it with a pargma
Code:
#pragma warning(disable: 4312)
you have to put that before any includes.
Re: Warning C4312 (64-Bit portability)
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