title: _Pragma and macro substitution
body: <p>In implementing my own C11 compiler, I'm trying to figure out how exactly to handle the <code>_Pragma</code> keyword/operator. C11 §6.10.9 describes <code>_Pragma</code> as being an operator, so it seems possible to redefine it with macros, i.e. <code>#define _Pragma(x) SOME_OTHER_MACRO(x)</code>. Further, the statement <code>#undef _Pragma</code> should have no effect (assuming no prior <code>#define</code> of <code>_Pragma</code>). This is similar to how keywords can be <code>#define</code>d, such as the old VC++ hack <code>#define for if (0) ; else for</code>. However, because the <code>_Pragma</code> operator is evaluated during translation phase 3, the same phase as executing preprocessor directives, it's not clear whether this is an exception; the standard doesn't mention whether its undefined behavior to use <code>_Pragma</code> as a macro name.</p>
  
  <p>I did some testing with GCC using the following code:</p>
  
  <pre><code>#define PRAGMA _Pragma
  PRAGMA("message \"hi\"")
  
  _Pragma ("message \"sup\"")
  
  #undef PRAGMA
  
  #undef _Pragma
  //#define _Pragma(x)
  _Pragma("message \"hello\"")
  </code></pre>
  
  <p>Compiling with <code>gcc -std=c11 -pedantic -Wall -Wextra -c</code> outputs:</p>
  
  <pre><code>tmp.c:2:1: note: #pragma message: hi
   PRAGMA("message \"hi\"")
   ^
  tmp.c:4:1: note: #pragma message: sup
   _Pragma ("message \"sup\"")
   ^
  tmp.c:8:8: warning: undefining "_Pragma" [enabled by default]
   #undef _Pragma
          ^
  tmp.c:10:9: error: expected declaration specifiers or ‘...’ before string constant
   _Pragma("message \"hello\"")
           ^
  </code></pre>
  
  <p>If I add the line <code>#undef _Alignof</code>, GCC doesn't complain about it.</p>
  
  <p>This suggests that GCC implements <code>_Pragma</code> through a macro (via the warning message), and that undefining it results in a compile error. If I uncomment <code>#define _Pragma(x)</code>, the error goes away (as the string literal disappears).</p>
  
  <p>So, my questions are:</p>
  
  <ol>
  <li>Are implementations allowed to define <code>_Pragma</code> as just a macro, and not implement it as an operator?</li>
  <li>If not, is GCC wrong in doing so?</li>
  <li>if <code>_Pragma</code> is supposed to be an operator, is it undefined behavior to define <code>_Pragma</code> as a macro?</li>
  <li>Is there any ordering between <code>_Pragma</code> evaluation and other preprocessor directives? Or do they have the same "precedence" (i.e. they're evaluated in-order)?</li>
  </ol>
  
  <p>Again, looking through the C11 standard does not mention anything about <code>_Pragma</code> other than it's an operator that can be used for <code>#pragma</code> directives.</p>