locked
32-bit / 64-bit Conversion RRS feed

  • Question

  • I want a single source code for 32-bit and 64-bit version

    I have a function like this...

    int CUtils::RoundToInt(double dValue)
    {
    #ifdef _DEBUG
     assert(dValue > static_cast<double>(INT_MIN / 2) - 1.0);
        assert(dValue < static_cast<double>(INT_MAX / 2) + 1.0);
    #endif
    
     const float round_to_nearest = 0.5f;
     int i;
     __asm
     {
      fld dValue
            fadd st, st (0)
            fadd round_to_nearest
            fistp i
            sar i, 1
     }
     return (i);
    }

    Now using conditional compile flags (#ifdef <flag>, #endif) How can I put a condition, that if it uses 32-bit PC, then it should use RoundToInt(double dValue) and in case of 64-bit it should use [B]RoundToInt64[/B](double dValue) function?

    Adeel

    Tuesday, October 27, 2015 6:54 AM

Answers

All replies

  • IsWow64Process ?
    please refer: https://msdn.microsoft.com/en-us/library/windows/desktop/ms684139%28v=vs.85%29.aspx?f=255&MSPPError=-2147217396

    Visual C++ enthusiast, like network programming and driver development. At present is being engaged in the WinCE/Windows Mobile platform embedded development.

    Tuesday, October 27, 2015 8:09 AM
  • I want a single source code for 32-bit and 64-bit version Now using conditional compile flags (#ifdef <flag>, #endif)

    For the MS C++ compiler, use the _WIN64 macro definition:
    https://msdn.microsoft.com/en-us/library/b0084kay.aspx

    Dave

    • Proposed as answer by chchlll Wednesday, November 4, 2015 6:50 AM
    • Marked as answer by Shu 2017 Saturday, November 7, 2015 1:31 PM
    Tuesday, October 27, 2015 8:23 AM
  • Hi, maverick786us,

        Is your problem solved?

    Best regards,

    chchlll

    • Edited by chchlll Wednesday, November 4, 2015 6:45 AM
    Wednesday, November 4, 2015 6:45 AM