Quantcast
Viewing all articles
Browse latest Browse all 14

Visual C++: Assert in Release Mode

Problem

In Visual C++, assertions are disabled in Release mode and enabled in Debug mode of the solution. I find assertions to be cheap and effective means of capturing programmer errors and would like assertions to be invoked during Release mode too.

Solution

assert is a macro and its existence during compilation is controlled by the definition of the NDEBUG identifier. If NDEBUG is defined, assertions are disabled. As you can guess, by default, NDEBUG is defined in Release mode.

So, to enable assertions in Release mode, go to the project properties → C/C++ → Preprocessor → Preprocessor Definitions and remove NDEBUG.

Tried with: Visual C++ 2008


Image may be NSFW.
Clik here to view.
Image may be NSFW.
Clik here to view.

Viewing all articles
Browse latest Browse all 14

Trending Articles