开发者

Windows: preventing assert() failures from opening the debug popup

How can I prevent the debug popup window from appearing when an assertion fails on a Windows machine? The app I'm writing is console based and I'm using assert() to test certain things when it's executed in test mode. I'm using MinGW + GCC 4.

Edit: This is the test program.

#include <stdlib.h>
#include <assert.h>

int main(void) {
    _set_error_mode(_OUT_TO_STDERR);
    assert(0 == 1);
    return EXIT_SUCCESS;
}

Flags: gcc -mwindows -pedantic -Wall -Wextra -c -g -Werror -MMD -MP -MF ...

开发者_StackOverflow社区

Tried without -mwindows as well. I still get the debug popup no matter what. This is on a Vista x86 machine.


There are many ways you can do that. The crudest is to redefine the assert macro (see the mingw assert.h header). You can also call (which is what I would advise):

_set_error_mode (_OUT_TO_STDERR);

Edit: Really, it works for me:

#include <stdlib.h>
#include <assert.h>

int main (void)
{
  _set_error_mode (_OUT_TO_STDERR);
  assert (0 == 1);
  return 0;
}

Compile with gcc -mwindows, it doesn't show the dialog box at runtime. Remove the line with _set_error_mode, and it shows the dialog box. If it doesn't work for you, please give a complete example.


Here is what I use, and that seems to work:

SetErrorMode (SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX | SEM_NOOPENFILEERRORBOX);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜