title: Gnu C++ macro __cplusplus standard conform?
body: <p>The Gnu C++ compiler seems to define <code>__cplusplus</code> to be <code>1</code></p>
  
  <pre><code>#include &lt;iostream&gt; 
  int main() {
    std::cout &lt;&lt; __cplusplus &lt;&lt; std::endl;
  }
  </code></pre>
  
  <p>This prints <code>1</code> with gcc in standard c++ mode, as well as in C++0x mode, with <a href="https://ideone.com/d6jdl">gcc 4.3.4</a>, and gcc 4.7.0.</p>
  
  <p>The C++11 FDIS says in <em>"16.8 Predefined macro names [cpp.predefined]"</em> that</p>
  
  <blockquote>
    <p>The name <code>__cplusplus</code> is defined to the <strong>value 201103L</strong> when compiling a C++ translation unit. (Footnote: It is intended that future versions of this standard will replace the value of this macro with a greater value. Non-conforming com-
    pilers should use a value with at most five decimal digits.)</p>
  </blockquote>
  
  <p>The old std C++03 had a similar rule.</p>
  
  <p><strong>Is the GCC deliberatly setting this to <code>1</code>, because it is "non-conforming"</strong>?</p>
  
  <p>By reading through that list I thought that I could use <code>__cplusplus</code> to check in a portable way if I have a C++11 enabled compiler. But with <em>g++</em> this does not seem to work. I know about the <code>...EXPERIMENTAL...</code> macro, but got curious why <em>g++</em> is defining <code>__cplusplus</code> this way.</p>
  
  <p>My original problem was switch between different null-pointer-variants. Something like this:</p>
  
  <pre><code>#if __cplusplus &gt; 201100L
  #  define MYNULL nullptr
  #else
  #  define MYNULL NULL
  #endif
  </code></pre>
  
  <p><strong>Is there a simple and reasonably portable way to implement such a switch?</strong></p>