title: C: What is the use of 'extern' in header files?
body: <p>Pardon me if this sounds a question that has been asked many times but I assure you this is a little different.</p>
  
  <p>I use Codeblocks for C programming and lately I have started to wonder why would someone use a header file in C. I understand it is used for declaring and/or defining variables structures. But here is something i tried and now I am confused.</p>
  
  <p>I have a header file named </p>
  
  <p><strong>test1.h</strong></p>
  
  <pre><code>#ifndef TEST1_H_INCLUDED
  #define TEST1_H_INCLUDED
  
  static int testvar = 233;
  extern int one;
  extern void show();
  
  #endif // TEST1_H_INCLUDED
  </code></pre>
  
  <p>and two other files</p>
  
  <p><strong>headertest.c</strong></p>
  
  <pre><code>#include"test1.h"
  #include&lt;stdio.h&gt;
  
  int one = 232;
  
  int main()
  {
      testvar = 12;
      printf("The address of one is %p and value is %d",&amp;testvar,testvar);
      printf("value of one is %d",one);
      show();
      return 0;
  }
  </code></pre>
  
  <p><strong>headertest2.c</strong></p>
  
  <pre><code>#include "test1.h"
  #include&lt;stdio.h&gt;
  
  extern int one;
  extern void show()
  {
      //extern int one;
      testvar = 34;
      printf("\nThe address of one is %p and value is %d",&amp;testvar, testvar);
      printf("The value of one is %d", one);
  }
  </code></pre>
  
  <p>Now my point is that even if i comment out the declaration 
  extern int one;
  extern void show();
  from the header file test1.h I get no warning or error during compilation and execution. When I can directly access int one and void show() from headertest.c because of them having external linkage implicitly then whats the use of Header file here? Why would someone declare some variable or function as extern in a header file that can otherwise be accessed directly!!</p>
  
  <p>Thank you</p>