title: Rationale of static declaration followed by non-static declaration allowed but not vice versa
body: <p>This code will compile and is well defined under current C standards:</p>
  
  <pre><code>static int foo(int);
  extern int foo(int);
  </code></pre>
  
  <p>The standard specifies that in this situation (<em>C11: 6.2.2 Linkages of identifiers (p4)</em>):</p>
  
  <blockquote>
    <p>For an identifier declared with the storage-class specifier extern in
    a scope in which a prior declaration of that identifier is visible,<sup>31)</sup>
    if the prior declaration specifies internal or external linkage, the
    linkage of the identifier at the later declaration is the same as the
    linkage specified at the prior declaration. [...]</p>
  </blockquote>
  
  <p>... which means that the <code>int foo(int)</code> function is declared <code>static int foo(int)</code>.</p>
  
  <p>Swapping these declarations around like this:</p>
  
  <pre><code>extern int foo(int);
  static int foo(int);
  </code></pre>
  
  <p>...gives me a compiler error using GNU GCC:</p>
  
  <blockquote>
    <p>static declaration of 'foo' follows non-static declaration</p>
  </blockquote>
  
  <p>My question is: What is the design rationale behind the second case being an error and not handled in a similar way as the first case? I suspect it has something to do with the fact that separate translation units are easier to manage and <code>#include</code>? I feel as though without understanding this, I can open myself up to some mistakes in future C projects.</p>