简体   繁体   English

如何检查单个#ifdef中是否定义了多个宏之一?

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

I have some C++ code, and want to perform an action if the __APPLE__ or __linux macros are defined. 我有一些C ++代码,并希望如果执行一个动作__APPLE____linux宏定义。

If I did it as a normal if conditional, it would be easy using || 如果我在正常if下将其作为正常条件,那么使用||会很容易 :

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

But as of what I know there is no || 但据我所知,没有|| operator for #ifdef statements. #ifdef语句的运算符。 How would I check if __APPLE__ or __linux is defined using a single #ifdef statement? 我将如何检查是否__APPLE____linux使用单一定义#ifdef语句?

You can't in a single #ifdef would a single #if do instead? 你不能在一个#ifdef单一的#if代替吗?

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

this also works if you prefer 如果您愿意,这也有效

#if defined __APPLE__ || defined __linux

In my C++ there is. 在我的C ++中有。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM