#ifdef for 32-bit platform

后端 未结 11 1439
眼角桃花
眼角桃花 2020-12-30 00:37

In an application I maintain, we\'ve encountered a problem with file descriptor limitations affecting the stdlib. This problem only affects the 32-bit version of the standar

11条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-30 01:07

    I'm not sure if there is a universal #if def that is appropriate. The C++ standard almost certainly does not define one. There are certainly platform spcefic ones though.

    For example, Windows

    #if _WIN64 
    // 64 bit build
    #else
    // 32 bit build
    #endif
    

    EDIT OP mentioned this is a cross compile between Windows and Non-Windows using GCC and other compilers

    There is no universal macro that can be used for all platforms and compilers. A little bit of preprocessor magic though can do the trick. Assuming you're only working on x86 and amd64 chips the following should do the trick. It can easily be expanded for other platforms though

    #if _WIN64 || __amd64__
    #define PORTABLE_64_BIT
    #else
    #define PORTABLE_32_BIT
    #endif
    

提交回复
热议问题