deft_code deft_code - 3 years ago 296
C Question


Which preprocessor define should be used to specify debug sections of code?


#ifdef _DEBUG
#ifndef NDEBUG
or is there a better way to do it, e.g.
#define MY_DEBUG

I think
is Visual Studio specific, is NDEBUG standard?

Answer Source

Visual Studio defines _DEBUG when you specify the /MTd or /MDd option, NDEBUG disables standard-C assertions. Use them when appropriate, ie _DEBUG if you want your debugging code to be consistent with the MS CRT debugging techniques and NDEBUG if you want to be consistent with assert().

If you define your own debugging macros (and you don't hack the compiler or C runtime), avoid starting names with an underscore, as these are reserved.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download