用于标识UNIX派生系统的通用宏? (Linux,OSX,BSD,......)

时间:2011-10-27 14:33:23

标签: c macos unix macros c-preprocessor

我想知道为什么在MacOSX上没有定义宏__unix__

MacOSX不是BSD UNIX衍生产品吗?

如果我在代码中定义__unix__宏,我可以遇到一些问题吗?

一般来说,在检查当前平台时,我更喜欢这样做:

#ifdef __unix__
...
#endif

而不是:

#if defined(__unix__) || defined(__APPLE__) || defined(__linux__) || defined(BSD) ...
...
#endif

最好的选择是在一个地方定义我自己的宏吗? E.g:

#if defined(__unix__) || defined(__APPLE__) || defined(__linux__) || defined(BSD) ...
#define UNIX_
#endif

1 个答案:

答案 0 :(得分:4)

POSIX要求在_POSIX_VERSION中定义<unistd.h>(也可以通过sysconf(_SC_VERSION)访问),所以试试吧。