title: static declaration of m follows non-static declaration
body: <p>I am trying a small example to know about the static external variable and its uses. The static variable is of local scope and the external variable is of global scope.</p>
  
  <p><strong>static5.c</strong></p>
  
  <pre><code>#include&lt;stdio.h&gt;
  #include "static5.h"
  static int m = 25;
  int main(){
   func(10);
   return 0;
  }
  </code></pre>
  
  <p><strong>static5.h</strong></p>
  
  <pre><code>#include&lt;stdio.h&gt;
  int func(val){
   extern int m;
   m = m + val;
   printf("\n value is : %d \n",m);
  }
  </code></pre>
  
  <p><strong>gcc static5.c static5.h</strong></p>
  
  <p><strong>o/p :</strong></p>
  
  <pre><code>static5.c:3: error: static declaration of m follows non-static declaration
  static5.h:3: note: previous declaration of m was here
  </code></pre>
  
  <p><strong>EDITED</strong> </p>
  
  <p>The correct program :</p>
  
  <pre><code>a.c:
  #include&lt;stdio.h&gt;
  #include "a1_1.h"
  int main(){
   func(20);
   return 0;
  }
  
  a1.h:
  static int i = 20;
  
  a1_1.h:
  #include "a1.h"
  int func(val){
   extern int i;
   i = i + val;
   printf("\n i : %d \n",i);
  }
  </code></pre>
  
  <p>This works fine perfectly fine. But this is compiled into a single compilation unit. Hence could able to access the static variable . Across the compilation unit we cannot use the static variable by using the extern variable.</p>