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":
If I go to the settings of a default Visual Studio 2015 project "Preprocessor Definitions" is empty!
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With