#ifndef _KOK_ASSERT_H_
#define _KOK_ASSERT_H_
#pragma once
#ifdef WIN32
#ifndef _DEBUG
#define Assert(expr) (void)0
#else
#include <windows.h>
#include <cstdio>
#define _KOK_UNICODE_STRING(str) L##str
#define KOK_UNICODE_STRING(str) _KOK_UNICODE_STRING(str)
bool WSAssert(wchar_t* pExpr, wchar_t* pFile, unsigned uline)
{
wchar_t buffer[2*MAX_PATH];
swprintf(buffer, KOK_UNICODE_STRING("Assertion failed: %s/n at File: %s, Line: %d/n"), pExpr, pFile, uline);
MessageBoxW(NULL, buffer, KOK_UNICODE_STRING("Assertion failed!!!"), MB_OK);
return 0;
}
#define KOK_ASSERT(expr) /
if(!(expr)) /
{ /
WSAssert(KOK_UNICODE_STRING(#expr), KOK_UNICODE_STRING(__FILE__), __LINE__); /
__asm int 3 /
}
#endif
#endif
#endif
本文介绍了一种在Windows环境下用于调试的断言宏定义实现方式。该方法通过自定义的KOK_ASSERT宏,在调试模式下当表达式为假时显示错误信息并触发断点,帮助开发者快速定位问题。
1769

被折叠的 条评论
为什么被折叠?



