又一个轮子:MessageBox断言(assert)

自己写了如下代码:

#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,而且还比我详细!

https://docs.microsoft.com/en-us/previous-versions/visualstudio/visual-studio-2013/9sb57dw4(v=vs.120)

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.

 

posted @ 2020-08-07 14:23  天天2023  阅读(236)  评论(0)    收藏  举报