assert没有效果,求调试。Debug模式下,代码没有被优化。assert行设了断点,100%确定是运作到了。而且100%确保是效果没有assert弹窗

assert没有效果,求调试。Debug模式下,代码没有被优化。assert行设了断点,100%确定是运行到了。而且100%确保是效果没有assert弹窗。
本帖最后由 u013627061 于 2014-02-19 15:35:34 编辑
大神们,为了方便你们调试,

建议先在  assert(false);这行代码上,做个断点,确保assert(false);这行代码是执行了。


然后,麻烦帮忙思考一下,为什么assert(false);后,警告弹窗没有跳出来。

注意:是在Debug模式下,确保代码不被优化。

assert是在代码的第11行。


#include <Windows.h>
#include <assert.h>
  
int numWindow = 0;
  
LRESULT CALLBACK MyProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    if (numWindow > 0)
    {
        int ax = 0;
        assert(false);
        int bx = 0;
        int cx = 0;
    }
    return ::DefWindowProcW(hWnd, uMsg, wParam, lParam);
}
  
  
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine, int nCmdShow)
{
    const wchar_t * wndClassName = L"myWindow";
  
    WNDCLASSW wc = { 0 };
    wc.style = NULL;
    wc.lpfnWndProc = MyProc;
    wc.cbClsExtra = NULL;
    wc.cbWndExtra = NULL;
    wc.hInstance = NULL;
    wc.hIcon = NULL;
    wc.hCursor = NULL;
    wc.hbrBackground = (HBRUSH)COLOR_BACKGROUND;
    wc.lpszMenuName = NULL;
    wc.lpszClassName = wndClassName;
  
    if (!RegisterClassW(&wc))
    {
        return false;
    }
  
    HWND h1 = CreateWindowExW(NULL, wndClassName, L"win1", NULL, 0, 0, 0, 0, NULL, NULL, NULL, NULL);
    numWindow++;
    HWND h2 = CreateWindowExW(NULL, wndClassName, L"win2", NULL, 0, 0, 0, 0, NULL, NULL, NULL, NULL);
    numWindow++;
  
    MSG msg = { 0 };
    while (GetMessageW(&msg, NULL, 0, 0))
    {
        TranslateMessage(&msg);
        DispatchMessageW(&msg);
    }
  
    return (int)(msg.wParam);
}





------解决方案--------------------
建议将assert(false);改为DebugBreak();