I don't know the real reason for MS not using the NDEBUG macro, and defining the _DEBUG instead. My my guess is that it is related to the definition of _ASSERT
instead of assert
.
The problem with assert()
is that the C standard defines requires it to print a line to the console and abort
the program. But Windows programs don't usually have a console, so MS thought that it would be nice to pop up a window instead. But that assert()
pops up a window would not be standard compliant, so the developed a similar but different macro:_ASSERT
, and a different macro to control its behavior: _DEBUG
.
A similar mess exists with the _UNICODE
and UNICODE
macros, but that's another story...
Note that in the default configuration of a Visual C++ project, in debug mode _DEBUG
is defined, but NDEBUG
is not. While in release mode _DEBUG
is not defined, but NDEBUG
is. So for your own code, you can use any one of them. But naturally, if you want to be portable you should use NDEBUG
, as the _DEBUG
name is reserved to the compiler implementation.