在我的c/c++中如何区分代码,在GCC和Clang之间作为编译器?
我通常通过检查__ GNUC __
来编写涉及GCC的代码。现在,我想编写一些对GCC和Clang行为不同的代码 - 但似乎Clang也定义了__ GNUC __
。我如何区分它们?
I usually write GCC-targeted code by checking __GNUC__
. Now I want to write some code which behaves differently for GCC and for clang - but it seems clang defines __GNUC__
as well. How do I differentiate between them?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
两者都定义
__ gnuc __
,但只有clang__ clang __
。因此,对于仅GCC而言,您会写:
当然,您可以通过分开这两个条件来适应仅GCC,仅叮当响。
注意:对于C和C ++,这是相同的。
While both define
__GNUC__
, only clang defines__clang__
.So, for GCC-only, you would write:
and of course you could adapt this to GCC-only, clang-only and other, by separating the two conditions.
Note: This is the same for C and for C++.