通用宏可以识别UNIX派生系统吗?(Linux,OSX,BSD等) [英] Common macro to identify a UNIX derived system? (Linux, OSX, BSD, ...)
本文介绍了通用宏可以识别UNIX派生系统吗?(Linux,OSX,BSD等)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道为什么在MacOSX上未定义宏 __ unix __
.
I wonder why on MacOSX the macro __unix__
is not defined.
MacOSX不是BSD UNIX衍生产品吗?
Isn't MacOSX a BSD UNIX derivative?
如果我在代码中定义了 __ unix __
宏,我会遇到一些问题吗?
If I define the __unix__
macro in my code, could I have some issues?
通常,在检查当前平台时,我喜欢做类似的事情:
In general, when checking the current platform, I prefer to do something like:
#ifdef __unix__
...
#endif
代替:
#if defined(__unix__) || defined(__APPLE__) || defined(__linux__) || defined(BSD) ...
...
#endif
最好的选择是在一个地方定义我自己的宏吗?例如:
Could the best option be to define my own macro in a single place? E.g.:
#if defined(__unix__) || defined(__APPLE__) || defined(__linux__) || defined(BSD) ...
#define UNIX_
#endif
推荐答案
POSIX要求在< unistd.h>
中定义 _POSIX_VERSION
(也可以通过 sysconf(_SC_VERSION)
),请尝试尝试.
POSIX requires _POSIX_VERSION
to be defined in <unistd.h>
(also accessible via sysconf(_SC_VERSION)
), so try that.
这篇关于通用宏可以识别UNIX派生系统吗?(Linux,OSX,BSD等)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文