title: Understanding this "extern inline" call in C99
body: <p>So I was reading some code and ran across this little snippet:</p>
  
  <pre><code>//file.h
  
  extern inline void foo();
  </code></pre>
  
  <p>With the implementation that looks like this:</p>
  
  <pre><code>//file.c
  MyType_t instance;
  inline void foo()
  {
      instance.someField++;
  }
  </code></pre>
  
  <p>Perhaps maybe I'm misunderstanding something, but it looks to me like the author intended to have an externally visible function which was also <code>inline</code> (which has internal linkage by default I believe). Because it's a tiny modifier function, I think the intention was to leverage inline substitution to avoid function overhead (which makes sense, as this runs on an embedded platform). But is this code actually eligible for inline substitution?</p>
  
  <p>My understanding is that <code>inline</code> provides that the compiler won't complain about multiple definitions (as per <a href="https://www.ibm.com/support/knowledgecenter/en/ssw_ibm_i_71/rzarg/inline_linkage.htm" rel="nofollow noreferrer">this link</a>), and that the function <a href="https://gustedt.wordpress.com/2010/11/29/myth-and-reality-about-inline-in-c99/" rel="nofollow noreferrer">may be eligible for inline substitution</a> (as an alternative to function-like macros).</p>
  
  <p>In this case though, because the definition is not in the header, there will still only be one "copy" of the inline function, so it is not eligible for inline substitution in files which include <code>file.h</code> (as far as I can tell). </p>
  
  <p>(from the second link above):</p>
  
  <blockquote>
    <p>the compiler must at least have seen a definition of the function. But if you have a classical big C project with functions that are implemented in different compilation units the compiler can’t do that integration for you. So you’d have to put the implementation of such candidate functions in header files.</p>
  </blockquote>
  
  <p>Therefore, it's only property remaining would be that the compiler won't complain about the multiply defined symbols, so that it could perhaps be defined differently in a different compilation unit. Though it's not so in this case, the symbol is only defined once for the record.</p>
  
  <p>So the crux of my question is: am I correct in concluding that this inline doesn't really serve much better purpose than this code:</p>
  
  <pre><code>//file.h
  extern void foo();
  
  //file.c
  MyType_t instance;
  void foo()
  {
      instance.someField++;
  }
  </code></pre>
  
  <p>And if the author wanted to make it eligible for inline substitution, would the solution have been to <a href="https://embeddedgurus.com/barr-code/2011/03/do-inline-function-bodies-belong-in-c-header-files/" rel="nofollow noreferrer">put the inline declaration and function body in the header</a>?</p>