#ifdef _DEBUG
// calls appropriate functions for message logging
#define LOGMESSAGE( stdStr ) gLogger.LogMessage( stdStr, __FILE__, __LINE__ );
// calls appropriate function for success logging
#define LOGSUCCESS( stdStr ) gLogger.LogSuccess( stdStr, __FILE__, __LINE__ );
// calls appropriate function for error logging
#define LOGFAILURE( stdStr ) gLogger.LogFailure( stdStr, __FILE__, __LINE__ );
#endif
#ifdef NDEBUG
// does nothing in release mode
#define LOGMESSAGE( stdStr )
// does nothing in release mode
#define LOGSUCCESS( stdStr )
// Logs failures in release mode
#define LOGFAILURE( stdStr ) gLogger.LogFailure( stdStr, __FILE__, __LINE__ );
#endif
假设我将宏称为如下
if ( SomeFunc() )
{
LOGSUCCESS("Success calling SomeFun()");
}
else
{
LOGFAILURE("Failure calling SomeFun()");
}
在发布模式下,LOGSUCCESS 为空白,这是否意味着“成功调用 SomeFunc()”字符串未编译到代码中并且不会存在于编译后的代码中,或者是剩余的,但宏不做任何事情它?
编辑:我的意思是它是否有效地将这样的代码保留在发布模式下?
if ( SomeFunc() )
{
"Success calling SomeFun()";
}
else
{
gLogger.LogFailure("Failure calling SomeFun()", __FILE__, __LINE__ );
}
或者
if ( SomeFunc() )
{
}
else
{
gLogger.LogFailure("Failure calling SomeFun()", __FILE__, __LINE__ );
}