Visual studio __VA_ARGS__ issue

后端 未结 1 1436
醉梦人生
醉梦人生 2021-02-06 17:45

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_         


        
相关标签:
1条回答
  • 2021-02-06 18:18

    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__));
    

    (Do note that __PRETTY_FUNCTION__ is a nonstandard extension that is not supported by Visual C++.)

    0 讨论(0)
提交回复
热议问题