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.

- 14,982
- 3
- 26
- 59
-
doesn't seem to be helping - I'm still seeing modal dialogs like: Debug Assertion Failed! File: minkernel\crts\ucrt\src\appcrt\heap\debug_heap.cpp Line: 996 Expression: __acrt_first_block == header – Marcin Jul 18 '18 at 23:42
-
This is a heap error. They always apear. You have a fatal error in your code that corrupts the heap! You should never ignore such an error! – xMRi Jul 19 '18 at 05:42
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.

- 68,205
- 6
- 94
- 158
-
doesn't seem to be helping - I'm still seeing modal dialogs like: Debug Assertion Failed! File: minkernel\crts\ucrt\src\appcrt\heap\debug_heap.cpp Line: 996 Expression: __acrt_first_block == header – Marcin Jul 18 '18 at 23:42
-
1This answer is important. Every other answer on the internet I could find for years assumes you have the code to recompile, a debugger attached, etc. Our code uses a driver which the manufacturer apparently shipped the debug version of, so the C runtime (CRT) pops up a dialog box about an assert failing every time the hardware gets into a bad state. It's not an exception, so you can't catch it or handle it, because the code is doing it on purpose. Calling _CrtSetReportMode() solves this. Thank you for this, our remote observatories are much easier to manage now. – Eliot Gillum Feb 05 '22 at 09:48
#define NDEBUG
before #include <assert.h>
to disable assert
macro.
You may so add this to pre-processor definition in project settings.

- 203,559
- 14
- 181
- 302
-
Useful information, however MFC `ASSERT` is not the same thing as the standard library `assert` and is controlled differently. – bames53 Jul 29 '16 at 23:20
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.

- 942
- 9
- 15
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.

- 31
- 5