title: C preprocessor concatenation outside of #define
body: <p>I was wondering <em>why</em> we can't use token concatenation outside of <code>define</code>s.</p>
  
  <p>This comes up when I want these at the same time:</p>
  
  <ul>
  <li>conflict-free naming in a library (or for "generics")</li>
  <li>debugability; when using a <code>define</code> for this then the whole code gets merged into a line and the debugger will only show the line where the <code>define</code> was used</li>
  </ul>
  
  <p>Some people might want an example (<em>actual question is below that</em>):</p>
  
  <p>lib.inc:</p>
  
  <pre><code>#ifndef NAME
      #error includer should first define NAME
  #endif
  void NAME() { // works
  }
  // void NAME##Init() { // doesn't work
  // }
  </code></pre>
  
  <p>main.c:</p>
  
  <pre><code>#define NAME conflictfree
  #include "lib.inc"
  int main(void) {
      conflictfree();
      // conflictfreeInit();
      return 0;
  }
  </code></pre>
  
  <p>Error:</p>
  
  <pre><code>In file included from main.c:2:0:
  lib.h:6:10: error: stray '##' in program
   void NAME##Init();
            ^
  </code></pre>
  
  <p>The rule of thumb is "concat only in define". And if I remember correctly: The reason is because of the preprocessor-phases. 
  Question: <strong>Why</strong> does it not work. The phases-argument sounds like it was once an implementation-limitation (instead of a logical reason) and then found its way into the standard. What could be so difficult about accepting <code>NAME##Init()</code> if <code>NAME()</code> works fine?</p>