自己写了如下代码:
#define NOTICE(txt) MessageBox(NULL, txt, "错误", MB_OK | MB_ICONINFORMATION) #define ERR_S(txt) do { NOTICE(txt); exit(1); } while (0) #define err_if(condition) do { if (condition) ERR_S(#condition); } while (0)
一谷歌才发现,原来assert.h在windows上的实现可以自动弹出MessageBox,而且还比我详细!
assert (CRT) | Microsoft Docs
The destination of the diagnostic message depends on the type of application that called the routine. Console applications always receive the message through stderr. In a Windows-based application, assert calls the Windows MessageBox function to create a message box to display the message along with an OK button. When the user clicks OK, the program aborts immediately.