title: Does '#'-character have to be at the start of a line in the C preprocessor?
body: <p>I have programmed C for quite a while now. During this time I have learned that it is a common convention to put the "#"-character that comes before preprocessor-directives at column one.</p>
  
  <p>Example:</p>
  
  <pre><code> #include &lt;stdio.h&gt;
  
   int main(void) {
   #ifdef MACRO1
   #ifdef MACRO2
        puts("defined(MACRO1) &amp;&amp; defined(MACRO2)");
   #else
        puts("defined(MACRO1)");
   #endif
   #else
        puts("!defined(MACRO1)");
   #endif
        return 0;
   }
  </code></pre>
  
  <p>When people indent their preprocessor directives they usually do it like this:</p>
  
  <pre><code> #include &lt;stdio.h&gt;
  
   int main(void) {
   #ifdef MACRO1
   # ifdef MACRO2
       puts("defined(MACRO1) &amp;&amp; defined(MACRO2)");
   # else
       puts("defined(MACRO1)");
   # endif
   #else
       puts("!defined(MACRO1)");
   #endif
       return 0;
   }
  </code></pre>
  
  <p>I do not think that I have ever seen anyone format it like this:</p>
  
  <pre><code> #include &lt;stdio.h&gt;
  
   int main(void) {
   #ifdef MACRO1
    #ifdef MACRO2
       puts("defined(MACRO1) &amp;&amp; defined(MACRO2)");
    #else
       puts("defined(MACRO1)");
    #endif
   #else
       puts("!defined(MACRO1)");
   #endif
       return 0;
   }
  </code></pre>
  
  <p>My question is if the C language standard demands that the <code>#</code>-character should be in column one.</p>
  
  <p>So is the third option above even legal?</p>
  
  <p>If all above cases are legal then I want to know if this is legal.</p>
  
  <pre><code> #include &lt;stdio.h&gt;
  
   int main(void) {
   #ifdef MACRO
       puts("defined(MACRO)");
   /* Now there are other characters before the `#` */ #endif
       return 0;
   }
  </code></pre>
  
  <p>Here is the <code>#endif</code> no longer on the "start" of the line because there are other non-whitespace characters in the way.</p>
  
  <p>What seems weird about the last example is that <code>Vim</code> text-editor does not highlight the <code>#endif</code> that comes after the comment.</p>
  
  <p><img src="https://i.stack.imgur.com/VETIB.png" alt="Screenshot"></p>
  
  <p>All these examples I have given compiles without any warnings using <code>gcc</code> with the <code>-Wall -pedantic</code> flags turned on (including the last one with a comment before <code>#endif</code>).</p>
  
  <p>Note that I am just curious about the syntax. I always put <code>#</code>-character at column one like everyone else when I program. I would never write things like <code>++i; #endif</code> in serious projects.</p>