Is there any way to turn off asserts instead of switching to Release mode. I need to debug a code which make assertions really often and it slows down my work. These asserts are not related to the issue i am trying to solve, so for now they only slow down my progress, because they are called very often in one of my base classes. Now I don't have the time to improve their design, so can someone tell me if there is a way to turn off asserts while being in debug mode and using it's capabilities.
5 Answers
User _CrtSetReportMode
int iPrev = _CrtSetReportMode(_CRT_ASSERT,0); // Start Operation with no ASSERTs ... // Restore previous mode with ASSERTs _CrtSetReportMode(_CRT_ASSERT,iPrev); Instead of using 0, you can use _CRTDBG_MODE_DEBUG only.
2 Comments
You can use _set_error_mode or _CrtSetReportMode (see xMRi's answer) to alter failure reporting method and avoid modal dialog box. See code snippet there:
int main() { _set_error_mode(_OUT_TO_STDERR); assert(2+2==5); } Also note that assert failures are typically for a reason, and you want to fix code, not just suppress the report. By removing them from debug builds completely you are simply breaking good things built for you.
2 Comments
I don't have Visual Studio 2013, but the following works for me in Visual Studio 2015, so maybe the same or something similar works for VS 2013, too.
In your main() function, call
_set_abort_behavior(0, _WRITE_ABORT_MSG | _CALL_REPORTFAULT); In Visual Studio, go to Debug / Windows / Exception Settings. In the Exception Settings, go to Win32 Exceptions / 0xc0000420 Assertion Failed. Uncheck the box in front of that entry.
I need both of the above to suppress assertion pop-ups in Debug mode.
Comments
#define NDEBUG before #include <assert.h> to disable assert macro.
You may so add this to pre-processor definition in project settings.
1 Comment
ASSERT is not the same thing as the standard library assert and is controlled differently.You can add an compiler flag /DNDEBUG to turn off asserts. I feel this is cleaner since you don't have to change anything in your code.
Fromm the MSVC documentations:
You can turn off the assert macro without modifying your source files by using a /DNDEBUG command-line option.