Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Macro `__unix__` not defined in MacOS X

Tags:

unix

macos

macros

I noticed that in MacOS X (Lion), the macro __unix__ is not defined. Since MacOS has its roots in BSD UNIX, shouldn't that be the case?

Is it possible to let the compiler/preprocessor know that I want it to be considered a UNIX system?

like image 662
Pietro Avatar asked Aug 15 '11 09:08

Pietro


2 Answers

The predefined macros site suggests using:

#if defined(unix) || defined(__unix__) || defined(__unix)
# define PREDEF_PLATFORM_UNIX
#endif

To distinguish UNIX systems. They also have warning notes about a number of compilers that don't set any of these. Depending on why you care about what the platform is you might be better off looking at configure time (in configure.ac or whatever build system you're using).

like image 91
Flexo Avatar answered Oct 19 '22 20:10

Flexo


I think this site gives the most comprehensive answer.

In short, to include Apple platforms and common Unix platforms, you'll need:

#if defined(__unix__) || defined(__unix) || \
        (defined(__APPLE__) && defined(__MACH__))
...
#endif
like image 30
Yongwei Wu Avatar answered Oct 19 '22 19:10

Yongwei Wu