C 预处理器测试多个宏的定义

发布于 2024-07-23 08:16:32 字数 387 浏览 6 评论 0原文

我搜索了该网站,但没有找到我正在寻找的答案,所以这是一个非常简单的问题。

我正在尝试做这样的事情:

#ifdef _WIN32 || _WIN64
     #include <conio.h>
#endif

我怎样才能做这样的事情? 我知道 _WIN32 是为 32 位和 64 位窗口定义的,所以我可以使用其中任何一个来进行窗口检测。 我更感兴趣的是我是否可以使用像预处理器指令那样的逻辑运算符,如果是的话如何使用,因为上面的方法不起作用。

用 gcc 编译我得到:

警告:#ifdef 指令末尾有额外的标记,它基本上只采用第一个宏并忽略其余部分。

I searched the site but did not find the answer I was looking for so here is a really quick question.

I am trying to do something like that :

#ifdef _WIN32 || _WIN64
     #include <conio.h>
#endif

How can I do such a thing? I know that _WIN32 is defined for both 32 and 64 bit windows so I would be okay with either for windows detection. I am more interested in whether I can use logical operators like that with preprocessor directives, and if yes how, since the above does not work.

Compiling with gcc I get :

warning: extra tokens at end of #ifdef directive , and it basically just takes the first MACRO and ignores the rest.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

棒棒糖 2024-07-30 08:16:32

尝试:

#if defined(_WIN32) || defined(_WIN64)
// do stuff
#endif

define 宏测试名称是否已定义并允许您应用逻辑运算符的结果。

Try:

#if defined(_WIN32) || defined(_WIN64)
// do stuff
#endif

The defined macro tests whether or not a name is defined and lets you apply logical operators to the result.

少女七分熟 2024-07-30 08:16:32

您必须使用 #if 和特殊运算符 define

You must use #if and special operator defined

埖埖迣鎅 2024-07-30 08:16:32

我认为应该可以这样:

#if defined block1 || defined block2 /*or any other boolean operator*/
   /*Code*/
#endif

更多信息

I think it should be possible this way:

#if defined block1 || defined block2 /*or any other boolean operator*/
   /*Code*/
#endif

More information here

已下线请稍等 2024-07-30 08:16:32

使用定义:

#if defined(A) || defined(B)
    #include <whatever.h>
#endif

Use defined:

#if defined(A) || defined(B)
    #include <whatever.h>
#endif
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文