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

后端 未结 6 1746
悲哀的现实
悲哀的现实 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:19

    It all depends.

    Each macro specifies something different in meaning.
    See: https://developer.apple.com/library/mac/documentation/Porting/Conceptual/PortingUnix/compiling/compiling.html#//apple_ref/doc/uid/TP40002850-SW13

    __APPLE__

    This macro is defined in any Apple computer.

    __APPLE_CC__

    This macro is set to an integer that represents the version number of the compiler. This lets you distinguish, for example, between compilers based on the same version of GCC, but with different bug fixes or features. Larger values denote later compilers.

    __OSX__

    Presumably the OS is a particular variant of OS X

    So given the above definitions I would use __APPLE__ to distinguish apple specific code.

提交回复
热议问题