How do I check if one of multiple macros is defined in a single #ifdef?

给你一囗甜甜゛ 提交于 2019-12-18 03:56:51

问题


I have some C++ code, and want to perform an action if the __APPLE__ or __linux macros are defined.

If I did it as a normal if conditional, it would be easy using ||:

if (something || something) { .. code .. }

But as of what I know there is no || operator for #ifdef statements. How would I check if __APPLE__ or __linux is defined using a single #ifdef statement?


回答1:


You can't in a single #ifdef would a single #if do instead?

#if defined(__APPLE__) || defined(__linux)

this also works if you prefer

#if defined __APPLE__ || defined __linux



回答2:


In my C++ there is.

#if defined(__APPLE__) || defined(__linux)
  // ...
#endif


来源:https://stackoverflow.com/questions/16378734/how-do-i-check-if-one-of-multiple-macros-is-defined-in-a-single-ifdef

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!