title: How can I conditionally include #ident directives in a macro?
body: <p>A bug in gcc-4.4 causes the <code>#ident</code> directive to emit a warning.  We don't allow warnings in our compiler (-Werror) so I need to turn these off when compiled on certain GCC compiler versions.  (See <a href="https://stackoverflow.com/questions/3650222/best-replacement-for-gcc-ident">Best replacement for GCC #ident</a>)</p>
  
  <pre><code>$ echo '#ident "FAILS on gcc-4.3.3"' &gt; test.c
  $ gcc-4.4 -c test.c
  test.c:1: warning: #ident is a deprecated GCC extension
  </code></pre>
  
  <p>Since these occur in several locations I want to replace them with a macro which would conditionally emit either nothing (or something that approximates <code>#ident</code>) on those "bad" compilers or with the actual <code>#ident</code> directive on all others.  Ideally, something like this:</p>
  
  <pre><code># test2.c
  #ifndef HAS_HASH_IDENT
  #  define IDENT(x) //-- NO-OP
  #else
  #  define IDENT(x) #ident x
  #endif
  </code></pre>
  
  <p>This doesn't work because the preprocessor chokes on the <code>#</code> of <code>#ident</code>, as it is interpreted as the stringize operator when used in a macro.</p>
  
  <pre><code>$ gcc-4.5 -Wall -E test2.c
  test2.c:4:22: error: '#' is not followed by a macro parameter
  </code></pre>
  
  <p>I tried several macro redirection tricks, but nothing I came up with would satisfy the preprocessor.</p>
  
  <p>Is something like this even possible?</p>
  
  <hr>
  
  <p>Note: The <code>#ident</code> directive is passed on intact to the compiler by the preprocessor, so the problem I'm having is <strong>not</strong> restricted by some sort of preprocessor recursion limitation.</p>
  
  <pre><code>$ gcc-4.5 -E test.c         
  # 1 "test.c"
  # 1 "&lt;built-in&gt;"
  # 1 "&lt;command-line&gt;"
  # 1 "test.c"
  #ident "FAILS on gcc-4.3.3"
  </code></pre>