Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This appears to be an (undocumented) "GNU extension": [<em>correction</em>: I finally found a mention in the docs. See below.]</p> <p>The following command uses the <code>-dM</code> option to print all preprocessor defines; since the input "file" is empty, it shows exactly the predefined macros. It was run with gcc-4.7.3 on a standard ubuntu install. You can see that the preprocessor is standard-aware. In total, there 243 macros with <code>-std=gnu99</code> and 240 with <code>-std=c99</code>; I filtered the output for relevance. </p> <pre><code>$ cpp --std=c89 -dM &lt; /dev/null | grep linux #define __linux 1 #define __linux__ 1 #define __gnu_linux__ 1 $ cpp --std=gnu89 -dM &lt; /dev/null | grep linux #define __linux 1 #define __linux__ 1 #define __gnu_linux__ 1 #define linux 1 $ cpp --std=c99 -dM &lt; /dev/null | grep linux #define __linux 1 #define __linux__ 1 #define __gnu_linux__ 1 $ cpp --std=gnu99 -dM &lt; /dev/null | grep linux #define __linux 1 #define __linux__ 1 #define __gnu_linux__ 1 #define linux 1 </code></pre> <p>The "gnu standard" versions also <code>#define unix</code>. (Using <code>c11</code> and <code>gnu11</code> produces the same results.)</p> <p>I suppose they had their reasons, but it seems to me to make the default installation of gcc (which compiles C code with <code>-std=gnu89</code> unless otherwise specified) non-conformant, and -- as in this question -- surprising. Polluting the global namespace with macros whose names don't begin with an underscore is not permitted in a conformant implementation. (6.8.10p2: "Any other predefined macro names shall begin with a leading underscore followed by an uppercase letter or a second underscore," but, as mentioned in Appendix J.5 (portability issues), such names are often predefined.)</p> <p>When I originally wrote this answer, I wasn't able to find any documentation in gcc about this issue, but I did finally discover it, not in <a href="https://gcc.gnu.org/onlinedocs/gcc-5.3.0/gcc/index.html#toc_C-Implementation">C implementation-defined behaviour</a> nor in <a href="https://gcc.gnu.org/onlinedocs/gcc-5.3.0/gcc/C-Extensions.html#C-Extensions">C extensions</a> but in the <code>cpp</code> manual section <a href="https://gcc.gnu.org/onlinedocs/gcc-5.3.0/cpp/System-specific-Predefined-Macros.html">3.7.3</a>, where it notes that:</p> <blockquote> <p>We are slowly phasing out all predefined macros which are outside the reserved namespace. You should never use them in new programs&hellip;</p> </blockquote>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload