如果没有给出宏的定义,则对宏有疑问 [英] Doubt on Macros , if definition of macro is not given
本文介绍了如果没有给出宏的定义,则对宏有疑问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
此处"#define add"未给出定义.
当我对宏调用"add"进行评论时,它不会对o/p产生任何影响.
Here "#define add " no definition is given for it.
When I comment macro call "add", it make no impact on o/p.
//add
addP
结果
------
addadd1
Result
------
addadd1
add
//addP
结果
------
没有o/p
Result
------
no o/p
#include <stdio.h>
#define add
#define addP \
printf("add"); \
printf("add1");
int main(void) {
add
addP
return 0;
}
输出
======
addadd1
Output
======
addadd1
推荐答案
addP
是一个宏,它会生成一些代码,如使用时所见.add
是不执行任何操作但可以在预处理程序语句中进行测试的宏.尝试添加以下代码:
addP
is a macro that generates some code, as you can see when you use it.add
is a macro that does nothing but can be tested in preprocessor statements. Try adding the following code:
#ifdef add
printf("add is defined");
#else
printf("add is not defined");
#endif
现在编译并运行,首先使用#define add
,然后不使用它.
now compile and run, first with #define add
, and secondly without it.
这篇关于如果没有给出宏的定义,则对宏有疑问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文