title: Multiple includes of same header file in project: C vs C++
body: <p>Here I have an example project with two source files and a header file, as follows:</p>
  
  <p>main.c:</p>
  
  <pre><code>#include&lt;stdio.h&gt;                                                               
  #include "personal.h"                                                           
  int main(){                                                                     
      i = 5;                                                                        
      printf("Value is %d\n",i);                                                    
      return 0;                                                                     
   }
  </code></pre>
  
  <p>sub.c:</p>
  
  <pre><code>#include "personal.h"                                                           
  // do nothing
  </code></pre>
  
  <p>and finally personal.h:</p>
  
  <pre><code>#pragma once                                                                    
  int i; 
  </code></pre>
  
  <p>Each of the .c file includes the personal.h, which is `guarded'. I compile with gcc, all goes fine:</p>
  
  <pre><code>&gt;gcc sub.c main.c -o out
  &gt;./out 
  Value is 5
  </code></pre>
  
  <p>But with g++, this happens:</p>
  
  <pre><code>&gt;g++ sub.c main.c -o out
  /tmp/cctYwVnO.o:(.bss+0x0): multiple definition of `i'
  /tmp/ccPElZ27.o:(.bss+0x0): first defined here
  collect2: error: ld returned 1 exit status
  </code></pre>
  
  <p>Is there anything fundamentally different between C++ and C in terms of how files are linked, preprocessor activity etc? I tried the same with other compilers like clang and the same happens. I am perhaps missing something silly here. </p>