title: Preprocessor token pasting in GCC’s _Pragma operator
body: <p>I’m trying to do something similar to <a href="https://stackoverflow.com/q/4782049/1968">another question</a>, namely, conditionally include OpenMP pragmas in my program. However, I want to go one step further and avoid that the user needs to specify <code>omp</code> every time they use the pragma. In other words, I want the following code to compile:</p>
  
  <pre><code>#include &lt;cstdio&gt;
  #include &lt;omp.h&gt;
  
  #ifdef _OPENMP
  #   define LIB_PRAGMA_OMP(x) _Pragma("omp " #x)
  #else
  #   define LIB_PRAGMA_OMP(x)
  #endif
  
  int main() {
      LIB_PRAGMA_OMP(parallel) {
          std::printf("Hello from thread %d\n", omp_get_thread_num());
      }
  }
  </code></pre>
  
  <p>Unfortunately, this doesn’t work. The compiler complains:</p>
  
  <blockquote>
    <p>error: <code>_Pragma</code> takes a parenthesized string literal</p>
  </blockquote>
  
  <p>If I use the following form, it works, though:</p>
  
  <pre><code>#define LIB_PRAGMA_OMP(x) _Pragma(#x)
  
  …
  
  LIB_PRAGMA_OMP(omp parallel) …
  </code></pre>
  
  <p>However, I’d really like to avoid this redundancy. <strong>How can I paste the (stringified) tokens correctly inside the <code>_Pragma</code> operator?</strong></p>