title: Does gcc define anything when -g is specified?
body: <p>Shortly, I want to know if gcc (or g++. I need it in <strong>C</strong>, but also am curious about c++) defines any special symbols if <code>-g</code> is enabled. Does it? If so, what symbols?</p>
  
  <p>In the search process I found out that:</p>
  
  <ul>
  <li><code>_DEBUG</code> is defined manually (by manually I mean <code>-D_DEBUG</code>) and is a habit taken from Visual C programmers  (because VC defines <code>_DEBUG</code> when compiling in debug mode)</li>
  <li><code>NDEBUG</code> is defined if NOT in debug mode. Although I found a few places saying this, I tried with my gcc and g++ in .c and .cpp files and in none of them with or without <code>-g</code> no such symbol was defined!</li>
  </ul>
  
  <p><strong>Edit</strong>: Let me demonstrate why I don't want to use a non-standard symbol:</p>
  
  <p>Imagine a kernel module that does something and also provides header files to be included in other kernel modules so that they can connect to this one.</p>
  
  <p>Now as a facility, in one of the header files I have:</p>
  
  <pre><code>#ifdef DEBUG &lt;-- This is what I need
  #define LOG(x, ...) printk("Some extra info"x, ##__VA_ARGS__);
  #else
  #define LOG(x, ...) printk("Without extra info"x, ##__VA_ARGS__);
  #endif
  </code></pre>
  
  <p>Note that the name is not really <code>LOG</code>, that's an example.</p>
  
  <p>Now, I can use any symbol for <code>DEBUG</code> myself, but then if someone includes my header, they may not define that symbol. Of course I can tell them "by the way, to get the headers in debug mode, define this other symbol", but that just doesn't sound right to me.</p>
  
  <p>I could define the symbol in a header and include it in all header files. This way, if they include one of my headers, they get the debug symbol too. The problem now is that, if they <em>don't</em> want to compile in debug mode, my headers still think they are in debug mode.</p>
  
  <p>So what I thought would be best was to use a symbol that is defined when <code>-g</code> is used, if there are any!</p>
  
  <h2>Update</h2>
  
  <p>So far I came to the conclusion that I could do something like this:</p>
  
  <p>how_to_build.h</p>
  
  <pre><code>#if !defined(NDEBUG)
  #define MY_DEBUG
  #endif
  </code></pre>
  
  <p>Usage:</p>
  
  <pre><code>#include "how_to_build.h"
  
  #ifdef MY_DEBUG
  // rest of the story
  </code></pre>
  
  <p>This way, the common option of <code>NDEBUG</code> removes my definition also. It still requires me to tell them to define it if they don't want to get the headers in debug mode.</p>