[英]C++ Debug macro failing compile in release mode
I'm using visual studio (2019) and I have this macro:我正在使用视觉工作室(2019)并且我有这个宏:
#if _DEBUG
#define EngineLog(vars, ...) Log(vars, ##__VA_ARGS__)
#endif
My log function this wraps around is:我的日志功能是:
template<typename... args>
static void Log(args && ... inputs)
{
std::osyncstream bout(std::cout);
bout << ENGINE_TAG;
([&]() {
bout << inputs;
} (), ...);
bout << "\n";
}
Obviously this works fine when I'm in debug mode, but when I use release mode I get:显然,当我处于调试模式时,这可以正常工作,但是当我使用发布模式时,我得到:
Error C3861 'EngineLog': identifier not found
I'm unsure why the compiler takes issue here, I was told it would remove the macro from the code when not defined but it seems not to be doing that.我不确定为什么编译器会在这里出现问题,我被告知它会在未定义时从代码中删除宏,但它似乎没有这样做。
if _DEBUG
is not defined, then EngineLog
is an unresolved name.如果
_DEBUG
未定义,则EngineLog
是未解析的名称。 You need to add a definition for the other case.您需要为另一种情况添加定义。
#if _DEBUG
#define EngineLog(vars, ...) Log(vars, ##__VA_ARGS__)
#else
#define EngineLog(vars, ...) (0 && Log(vars, ##__VA_ARGS__))
#endif
The syntax used here prevents any potential warnings about the variadic arguments being unused while at the same time preventing both the function from being called and its parameters being evaluated.此处使用的语法可防止任何有关未使用可变参数的潜在警告,同时防止调用函数及其评估其参数。
Looks like you need a #else
preprocessor case to define out the macro call with an empty expansion:看起来您需要一个
#else
预处理器案例来定义带有空扩展的宏调用:
#if _DEBUG
#define EngineLog(vars, ...) Log(vars, ##__VA_ARGS__)
#else
#define EngineLog(vars, ...)
#endif
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.