64,649
社区成员
发帖
与我相关
我的任务
分享
void dbg(const char* format, ...)
{
#ifdef qpDEBUG
char buf[4096];
char* p = buf;
va_list ap;
va_start(ap, format);
int n = vsnprintf_s(buf, sizeof(buf), _countof(buf), format, ap);
va_end(ap);
// buf-3 is room for CR/LF/NUL
p += (n < 0) ? _countof(buf) - 3 : n;
while (p > buf && isspace(p[-1]))
*--p = '\0';
*p++ = '\r';
*p++ = '\n';
*p = '\0';
OutputDebugStringA(buf);
#endif
}
void dbg(const wchar_t* format, ...)
{
#ifdef qpDEBUG
wchar_t buf[4096];
wchar_t* p = buf;
va_list ap;
va_start(ap, format);
int n = _vsnwprintf_s(buf, _countof(buf), format, ap);
va_end(ap);
// buf-3 is room for CR/LF/NUL
p += (n < 0) ? _countof(buf) - 3 : n;
while (p > buf && iswspace(p[-1]))
*--p = L'\0';
*p++ = L'\r';
*p++ = L'\n';
*p = L'\0';
OutputDebugStringW(buf);
#endif
}
void dbg(const string& str)
{
#ifdef qpDEBUG
dbg(str.c_str());
#endif
}
void dbg(const wstring& str)
{
#ifdef qpDEBUG
dbg(str.c_str());
#endif
}
void dbg(int i, int line, const char* file)
{
#ifdef qpDEBUG
if (line != 0)
dbg("%s, %d : %d", file, line, i);
else
dbg("%d", i);
#endif
}
void dbg(void* p, const char* file, int line)
{
#ifdef qpDEBUG
if (line != 0)
dbg("%s, %d : %x", file, line, p);
else
dbg("%x", p);
#endif
}