Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where are NDEBUG and _DEBUG Defined in Visual Studio 2015?

I can go to the settings of a default Visual Studio 2010 project and see NDEBUG or _DEBUG defined in "Configuration Properties">>"C/C++">>"Preprocessor"'s "Preprocessor Definitions": Visual Studio 2010 Project Settings

If I go to the settings of a default Visual Studio 2015 project "Preprocessor Definitions" is empty! Visual Studio 2015 Project Settings

I don't even see NDEBUG or _DEBUG mentioned at all in the Visual Studio 2015 .vcxproj. I know that it is correctly defined though because assert(false) only fires in the Debug configuration. Where has Microsoft tucked these definitions away in Visual Studio 2015? Is it possible for me to modify them, or has that been taken from me?

EDIT: Niall's answer is correct. What I didn't understand was that the assert happened differently if triggered in Release configuration. This program doesn't pop up an assert dialog, but it doesn't execute the system("pause") either:

void main() {
    assert(false);
    system("pause");
}

Instead when I run it in Release configuration from Visual Studio I see the console window pop up and immediately close, so I assumed the assert didn't fire cause I didn't see an assert dialog. However if I run the compiled Release executable from the terminal it immediately ends, but it outputs:

Assertion failed: false, file temp.cpp, line 9

So the assertion is firing in Release configuration, it just doesn't pop up an assert dialog. This means that NDEBUG is in fact not being defined.

like image 933
Jonathan Mee Avatar asked Oct 20 '22 00:10

Jonathan Mee


1 Answers

Generally these are defined as part of the additional pre processor defines/options and ultimately land up on the command line with a /D option switch.

Depending on the project configuration they could be inherited from a parent properties file so may not be immediately visible in the project.

The runtime switches /MD, /MT and the debug versions /MDd and /MTd define these as well; in particlar the _DEBUG. The MSDN documentation (here) for these provides more detail.

From experience, in the case of NDEBUG, it may be better to test #ifndef _DEBUG. I generally find that more consistent.

like image 191
Niall Avatar answered Nov 14 '22 21:11

Niall