3

I have the following sample code in one of my header files:

#ifdef _DEBUG
#define _DEBUG_NEW_REDEFINE_NEW 0
#include "debug_new.h"
#else
#define DEBUG_NEW new
#endif

The application which includes this header file is compiled using gcc compiler with -DDEBUG option.

Question:

Is _DEBUG is defined because of the -DDEBUG option?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
nitin_cherian
  • 6,405
  • 21
  • 76
  • 127

1 Answers1

4

-DDEBUG will only define DEBUG, not _DEBUG. To figure out why (or if) _DEBUG is getting defined, try building the source file that includes that header with

gcc --other_options source_file.cc -E -dD -o source_file.ii

(You may have to remove another -o flag in the command line.) Then source_file.ii will include #define lines for every macro that was defined, and # <lineno> <header> lines each time it changes header files.

You can read http://gcc.gnu.org/onlinedocs/gcc-4.6.2/gcc/Preprocessor-Options.html#index-dD-946 to see exactly what -dD does.

Jeffrey Yasskin
  • 5,171
  • 2
  • 27
  • 39