#ifdef for 32-bit platform

后端 未结 11 1422
眼角桃花
眼角桃花 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 00:52

    I would test it indirectly, via the maximum pointer value constant:

    #include 
    
    #if UINTPTR_MAX == 0xffFFffFF
    // 32-bit platform
    #elif UINTPTR_MAX == 0xffFFffFFffFFffFF
    // 64-bit platform
    #else
    #error Unknown platform - does not look either like 32-bit or 64-bit
    #endif
    

    This way you don't rely on any platform-specific define for architecture, but on the direct consequence of having a specific architecture - the pointer size.

提交回复
热议问题