title: Can I get the C++ preprocessor to send output during compilation?
body: <p>I have been debugging a particularly insidious bug which I now believe to be caused by unexpected changes which stem from different behavior when different headers are included (or not). </p>
  
  <p>This is not exactly the structure of my code but let's just take a look at this scenario:</p>
  
  <pre><code>#include "Newly_created_header_which_accidentally_undefines_SOME_DEFINE.h"
  
  // ...
  
  #ifdef SOME_DEFINE
      code_which_i_believe_i_am_always_running();
  #else 
      code_which_fails_which_i_have_forgotten_about(); // runtime error stack traces back here, but I don't know this... or maybe it's some strange linker error
  #endif
  </code></pre>
  
  <p>I search through my git commits and narrow down the cause of the bug, compiling and running my code countless times, only to find after several hours that the only difference required for causing the bug is the inclusion of what appears to be a completely benign and unrelated header. </p>
  
  <p>Perhaps this is a great argument for why the preprocessor basically just sucks. </p>
  
  <p>But I like it. The preprocessor is cool because it lets us make shortcuts. It's only that some of these shortcuts, when not used carefully, bite us in the butt pretty hard. </p>
  
  <p>So at this juncture it would have helped if I could use a directive like <code>#echo "Running old crashy code"</code> where I'll be able to see this <strong>during compilation</strong> so I could be tipped off immediately to start investigating why SOME_DEFINE was not defined. </p>
  
  <p>As far as I know the straightforward way of determining if SOME_DEFINE is defined is to do something like </p>
  
  <pre><code>#ifndef SOME_DEFINE
      printf("SOME_DEFINE not defined!!\n");
  </code></pre>
  
  <p>This will surely get the job done but there is no good reason for this task to be performed at runtime because it is entirely determined at compile-time. This is simply something I'd like to see at compile-time. </p>
  
  <p>That being said, in this situation, using the print (or log or even throwing an exception) may be an acceptable thing to do because I won't really care about slowing down or cluttering up the questionable code. But that doesn't apply if I have for instance two code paths both of which are important, and I just want to know at compile-time which one is being activated. I'd have to worry about running the code that does the preprocessor-conditioned print at the beginning of the program. </p>
  
  <p>This is really just a long-winded way of asking the question, "Can I echo a string to the output during compilation by using a preprocessor directive?" </p>