Which macro to wrap Mac OS X specific code in C/C++

后端 未结 6 1704
悲哀的现实
悲哀的现实 2020-12-13 03:32

While reading various C and C++ sources, I have encountered two macros __APPLE__ and __OSX__. I found plenty of use of __OSX__ in vari

6条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-13 04:37

    Use

    #if defined(__APPLE__) && defined(__MACH__)
    

    to distinguish Apple MacOS (not iOS).

    Regarding the "where does OSX come from":

    Some on-line lists of compiler macros (like this one) list __MACOSX__. Some forum comments (like these) claim __OSX__ exists. These are incorrect. There are no such macros predefined by OSX compilers, but they may be defined by specific project Makefiles and platform-detector scripts like GNU autoconf.

    Source: http://nadeausoftware.com/articles/2012/01/c_c_tip_how_use_compiler_predefined_macros_detect_operating_system

提交回复
热议问题