What C preprocessor conditional should I use for OS X specific code?

倾然丶 夕夏残阳落幕 提交于 2019-12-02 20:27:10

This list of operating system macros says the presence of both __APPLE__ and __MACH__ indicate OSX.

Also confirmed at line 18 of part of the source for fdisk.

__APPLE__ will tell you you're compiling on an Apple platform. Unless you need to support MacOS versions before OS X, that should be good enough. Alternately, you could use __APPLE__ and __MACH__ to make sure you're compiling on OS X.

If I remember correctly, it's __APPLE__ :)

This code example may help you -

if defined(__APPLE__)
#include "TargetConditionals.h"
  if (!defined(TARGET_OS_IPHONE) && !defined(TARGET_IPHONE_SIMULATOR))
 {
   //write your OSX specific code here
 } 

old style raw:

#ifdef WIN32
// windows.
#elif __APPLE__
// osx and ios.
#endif

This page contains a list of all OS predefined macros.

For mac OSX both the __APPLE__ && __MACH__ need to be defined.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!