多个宏章C preprocessor测试definedness [英] C Preprocessor testing definedness of multiple macros
问题描述
我搜索了网站,但没有发现我一直在寻找所以这里是一个非常简单的问题,答案
我试图做这样的事情:
的#ifdef _WIN32 || _WIN64
#包括LT&;&CONIO.H GT;
#万一
我怎样才能做这样的事情?我知道_WIN32为32位和64位Windows定义的,所以我会好起来的有两种用于Windows的检测。我更感兴趣的是我是否可以使用逻辑运算符一样,用preprocessor指令,如果是怎样的,因为上面没有工作。
用gcc编译我得到:
警告:在#ifdef指令月底多出的令牌,它基本上只需要第一个宏,忽略其余部分。
。
块引用>解决方案尝试:
#如果定义(_WIN32)||定义(_WIN64)
// 做东西
#万一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.
解决方案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.
这篇关于多个宏章C preprocessor测试definedness的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!