Code Yarns ‍👨‍💻
Tech BlogPersonal Blog

Visual C++: Assert in Release Mode

📅 2011-May-30 ⬩ ✍️ Ashwin Nanjappa ⬩ 📚 Archive

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