Visual Studio __VA_ARGS__问题 [英] Visual studio __VA_ARGS__ issue
本文介绍了Visual Studio __VA_ARGS__问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我运行cl/P test.cpp,文件和结果如下.
I run cl /P test.cpp, the file and result is as following.
test.cpp
#define FiltedLog( ...) \
if (logDetail) \
MP_LOG(LOG_INFO, __VA_ARGS__);
#define MP_LOG(level,fmt,...) \
BOOAT::LOG("MP", level, fmt, ##__VA_ARGS__)
#define LOG(tag,level,fmt,...) \
Log::log(tag, level, "%s: " fmt, __PRETTY_FUNCTION__, ##__VA_ARGS__)
int main ()
{
FiltedLog ( "abc", 1, 2);
}
Cl/P test.cpp:
Cl /P test.cpp :
#line 1 "test.cpp"
int main ()
{
if (logDetail) BOOAT::Log::log("MP", LOG_INFO, "%s: " "abc", 1, 2, __PRETTY_FUNCTION__ );;
}
我想知道为什么将__PRETTY_FUNCTION__
作为结果的最后一个参数.
我认为结果应该是:
I wonder why the __PRETTY_FUNCTION__
are put as the last arguments in the result.
I assume the result should be:
if (logDetail) BOOAT::Log::log("MP", LOG_INFO, "%s: " "abc", __PRETTY_FUNCTION__, 1, 2);;
这是VS 2010的错误吗?
Is it an bug of VS 2010?
推荐答案
是的,这是Visual C ++预处理器中的一个长期存在的错误.要解决此问题,请使用间接寻址:
Yes, this is a longstanding bug in the Visual C++ preprocessor. To work around it, use indirection:
#define INDIRECT_EXPAND(m, args) m args
#define FiltedLog( ...) \
if (logDetail) \
INDIRECT_EXPAND(MP_LOG, (LOG_INFO, __VA_ARGS__));
(请注意,__PRETTY_FUNCTION__
是Visual C ++不支持的非标准扩展.)
(Do note that __PRETTY_FUNCTION__
is a nonstandard extension that is not supported by Visual C++.)
这篇关于Visual Studio __VA_ARGS__问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文