#在visualc+中为uu noop定义实数函数名+;2013 我可以在Visual C++ 2008中使用发布(NDEUG)设置:

#在visualc+中为uu noop定义实数函数名+;2013 我可以在Visual C++ 2008中使用发布(NDEUG)设置:,c++,visual-studio-2013,visual-studio-2008,c-preprocessor,compiler-flags,C++,Visual Studio 2013,Visual Studio 2008,C Preprocessor,Compiler Flags,debug.h #ifdef _DEBUG void debug_printf(const char* format, ...); #else #define debug_printf(format, v) __noop #endif debug.cpp #include "stdafx.h" //#include "debug.h" is inside it void debug_printf(const char* format, ...) { //so muc

debug.h

#ifdef _DEBUG

void debug_printf(const char* format, ...);

#else

#define debug_printf(format, v)     __noop

#endif
debug.cpp

#include "stdafx.h"  //#include "debug.h" is inside it

void debug_printf(const char* format, ...) {
    //so much work here
}

在VisualC++ 2013中,我将在调试.CPP文件中获得编译错误。似乎我必须更改debug.h中的定义策略。但我想知道是否有编译器设置以旧的方式重新启用?

在第一种情况下也使用宏,让它调用实际函数(该函数的名称与宏不同)

在第二种情况下,只有一个空的宏体

使用


差不多

#ifdef _DEBUG
# define debug_printf(fmt, ...) real_debug_printf(fmt, __VA_ARGS__)
#else
# define debug_printf(fmt, ...)
#endif

如果未定义
\u DEBUG
,则宏
DEBUG\u printf
将被零替换(或者更确切地说,是一个空行)。

什么编译错误?为什么人们认为不发布它会有用?!错误消息很多:缺少“;”在{之前,意外的类型bla2…像那样,这是因为debug.cpp中的
debug\u printf
文本被替换为
\u noop
,所以它变成:
void\u noop(const char*format,…){
愿意举个例子吗?@suud当然,因为什么都不做(而且非常便携!)虽然
\uuu noop
似乎是特定于vert编译器的,但您不知道编译器是否确实为其生成了
nop
汇编指令。