Reputation: 5264
What is the difference between DEBUG and _DEBUG in vc++ in visual studio 2008.Is there any difference because in In my project,in some module preprocessor is DEBUG and in some module it is _DEBUG.
Upvotes: 9
Views: 4051
Reputation: 11
If the Codegeneration-setting of the project is anything with "debug", so the _DEBUG Macro is defined by the compiler. The corresponding compiler options are /MDd Multithreaded DLL, dynamic linkage to libc, DEBUG /MLd Single-Threaded, static linkage to libc, DEBUG (VC6) /MTd Multithreaded, static linkage to libc, DEBUG
The compiler option /LDd defines the _DEBUG Macro, too.
The DEBUG Macro is often explicitly defined in the Debug-Project-Setting.
Upvotes: 1
Reputation: 19841
It actually depends what macro use defined. As I know default VS2008 C++ project contains _DEBUG to be defined for debug configuration. It might happen that in your project there is custom DEBUG macro defined as well. Try to search for DEBUG definition.
By default you should always use _DEBUG.
Upvotes: 2
Reputation: 4247
In your own code you can check for any macro you want, so it doesn't matter which one to use.
But the libraries you use may behave different. E.g. the MSDN documentation about assert
states:
Assertion statements compile only when _DEBUG is defined. When _DEBUG is not defined, the compiler treats assertions as null statements.
So I would suggest to always use _DEBUG
.
Edit: According to MSDN you do not even have to define any special debug macro because the compiler will do it for you as soon as you specify a debug runtime library.
Upvotes: 6