Reputation: 6211
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 ...
Tried without -mwindows
as well. I still get the debug popup no matter what. This is on a Vista x86 machine.
Upvotes: 4
Views: 2158
Reputation: 121
Here is what I use, and that seems to work:
SetErrorMode (SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX | SEM_NOOPENFILEERRORBOX);
Upvotes: 2
Reputation: 12298
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.
Upvotes: 3