Skip to content

Instantly share code, notes, and snippets.

@lixingcong
Last active August 29, 2017 02:10
Show Gist options
  • Save lixingcong/bf9c4b2c0cc1d0f4e7396174d38473f2 to your computer and use it in GitHub Desktop.
Save lixingcong/bf9c4b2c0cc1d0f4e7396174d38473f2 to your computer and use it in GitHub Desktop.
debug output in MFC
// use C source code, not macro
void debug_printf(char *fmt,...){
#ifdef _DEBUG
va_list ap;
va_start(ap,fmt); // #include <stdarg.h>
vprintf(fmt,ap);
va_end(ap);
#endif
}
// or use the macro
// filename: debug.h
#if 0
// 调试用,输出到windows屏幕终端
#ifdef _DEBUG
#define debug_printf(fmt, ...) \
do{ \
_cprintf(fmt, __VA_ARGS__); \
}while(0)
#else
#define debug_printf(fmt, ...)
#endif
#endif
#include "debug.h"
#ifdef _DEBUG
if(!AllocConsole()) // 创建调试console
AfxMessageBox(_T("Fail to creat the console!"),MB_ICONEXCLAMATION);
debug_printf("Hello, I am the debug console!\n");
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment