|
-
March 7th, 2006, 09:04 AM
#1
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
 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?
Please don't forget to rate users who helped you!
-
March 7th, 2006, 10:01 AM
#2
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...
-
March 7th, 2006, 10:31 AM
#3
Re: Warning C4312 (64-Bit portability)
 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.
"inherit to be reused by code that uses the base class, not to reuse base class code", Sutter and Alexandrescu, C++ Coding Standards.
Club of lovers of the C++ typecasts cute syntax: Only recorded member.
Out of memory happens! Handle it properly!
Say no to g_new()!
-
March 7th, 2006, 11:06 AM
#4
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.
Please don't forget to rate users who helped you!
-
March 7th, 2006, 12:34 PM
#5
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.
-
March 7th, 2006, 12:53 PM
#6
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
Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
Convenience and productivity tools for Microsoft Visual Studio:
FeinWindows - replacement windows manager for Visual Studio, and more...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|