c定义多行宏? [英] c define multiline macro?
本文介绍了c定义多行宏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
#define DEBUG_BREAK(a)\
if ((a)) \
{\
__asm int 3;\
}
我已经如上所述定义了一个宏,并尝试使用它
I have defined a macro as above, and try to use it
#include "test_define.h"
int main()
{
DEBUG_BREAK(1 == 1);
return 0;
}
但是该示例将无法编译.编译器会抱怨括号未关闭.如果在源文件的末尾添加另一个}
,它将编译.
But this sample will not compile. The compiler would complain the parenthesis is not closed. If I add another }
in the end of the source file, it compiles.
此宏出了什么问题?
推荐答案
宏
#define DEBUG_BREAK(a)\
if ((a)) \
__asm int 3;
工作正常,但
#define DEBUG_BREAK(a)\
if ((a)) \
{\
__asm int 3;\
}
没有!而且我认为任何人都可以猜测为什么!新的生产线操作员就是麻烦大佬!
doesn't! And I think anyone could guess why!! The new line operator is the problem making guy!
需要
__asm int 3;\
}
为
__asm int 3; }
其中,;
注释掉它后面的内容(在汇编中).所以我们会错过一个}
.
where ;
comments out what follows it (in assembly). So we will miss a }
then.
这篇关于c定义多行宏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文