可变常量宏,数值常量前应为')' [英] Variadic macro expected ')' before numeric constant
本文介绍了可变常量宏,数值常量前应为')'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是实际的宏:
#ifdef DEBUG
#define debug(funcname, format, ...) \
printf(BOLD UNDERLINED REVERSE \
"DEBUG IN " __FILE__ \
" LINE " __LINE__ ":" \
RESET UNDERLINED REVERSE \
"In " funcname \
RESET REVERSE format RESET, ##__VA_ARGS__)
#else
#define debug(funcname, format, ...)
#endif
所有使用的常量都是定义明确的字符串常量.我用类似这样的名称来称呼它:
Where all the constant used are well defined string constants. I call it with something like:
char message[] = "Hello StackOverflow !\n";
debug("main()", "Message: %s\n", message);
但是我收到消息
错误:数值常量前应有'"debug("main()","Message:",message);
放在右括号中.
这很奇怪,因为我首先测试了宏,而现在该项目已经与团队一起进行了,因此无法正常工作...
It is weird because I first tested the macro, and now that the project has advanced with the team it doesn't work...
推荐答案
那是因为
" LINE " __LINE__ ":"
扩展为语法无效
" LINE " 42 ":"
因为 __ LINE __
是整数,而不是可以串联的字符串文字.
since __LINE__
is an integer, not a string literal that can be concatenated.
这篇关于可变常量宏,数值常量前应为')'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文