CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Jul 2005
    Location
    Germany
    Posts
    1,194

    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?
    Please don't forget to rate users who helped you!

  2. #2
    Join Date
    Oct 2000
    Location
    London, England
    Posts
    4,773

    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...

  3. #3
    Join Date
    Feb 2005
    Location
    Normandy in France
    Posts
    4,590

    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.
    "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()!

  4. #4
    Join Date
    Jul 2005
    Location
    Germany
    Posts
    1,194

    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!

  5. #5
    Join Date
    Jun 2002
    Posts
    1,417

    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.

  6. #6
    Join Date
    Aug 2000
    Location
    New York, NY, USA
    Posts
    5,656

    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
  •  





Click Here to Expand Forum to Full Width

Featured