What C preprocessor conditional should I use for OS X specific code?
Solution 1
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
.
Solution 2
__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.
Solution 3
If I remember correctly, it's __APPLE__
:)
Related videos on Youtube
klynch
I work at a Philadelphia startup where I wear many hats.
Updated on December 10, 2020Comments
-
klynch over 3 years
What C preprocessor conditional should I use for OS X specific code? I need to include a specific library if I am compiling for OS X or a different header if I am compiling for Linux.
I know there is
__APPLE__
but I don't know if that is a current conditional for OS X 10.x. -
Naseef Chowdhury over 10 yearsI believe this is for both MAC and iOS.