title: Should I deliberately inline functions across translation units in C99
body: <p>In my question I originally asked these four questions</p>
  
  <ol>
  <li>In C99 compilers, is the behavior of <code>inline</code> implementation defined when it comes to inlining across translation units?</li>
  <li>If so, should it be avoided?</li>
  <li>Is there some other generally accepted way of doing this?</li>
  <li>If my <code>inline</code> function doesn't get inlined everywhere, would I at least get some sort of linker error?</li>
  </ol>
  
  <p>After my OP I discovered that the first question has been discussed at length already in the following threads:</p>
  
  <ul>
  <li><a href="https://stackoverflow.com/questions/5229343/how-to-declare-an-inline-function-in-c99-multi-file-project?rq=1">How to declare an <code>inline</code> function in C99 multi-file project?</a></li>
  <li><a href="https://stackoverflow.com/questions/6312597/is-inline-without-static-or-extern-ever-useful-in-c99?rq=1">Is <code>inline</code> without <code>static</code> or <code>extern</code> ever useful in C99?</a></li>
  </ul>
  
  <p>There are more threads on this topic, but these two seemed to hit the nail on the head.</p>
  
  <p>So, based on these two discussions we can see that the answer to question 1 is YES. Compilers definitely have some freedom W.R.T. how they handle the <code>inline</code> specifier.</p>
  
  <p>We also see that for this to work <code>inline</code> functions <em>must</em> be defined in a header.</p>
  
  <p>Then beyond that the following options exist:</p>
  
  <ol>
  <li>The function definition in the header may have a <code>static</code> specifier.</li>
  <li>If the header definition does not have a <code>static</code> specifier, it may be declared via <code>extern</code> in some common header file that all C files calling the function will also <code>#include</code>.</li>
  <li>If methods 2 and 3 are not used, method 4 would be to declare this <code>inline</code> function via <code>extern</code> in every C file that wishes to call it.</li>
  </ol>
  
  <p>So, now that all of that explanation is out of the way, I would like to refocus this question on my original items #2 and #3 – should I even be doing this, and if so what's the most acceptable way?</p>
  
  <h1>Should I be doing this - or should this be avoided as much as possible?</h1>
  
  <p>Consider my application – I have a one line function in a driver that is called frequently (≈ several hundred times a second), but only from 3 or 4 other places. So using <code>inline</code> will not contribute to code bloat – in fact the result will be negligible. Gregory Pakosz outlines when to use an <code>inline</code> function and when not to nicely in <a href="https://stackoverflow.com/a/1932371/2344440">this answer</a>. So therefore, the answer would be very clear if this were one function being used in one translation unit. <em>But that's not what I am asking</em>.</p>
  
  <p>In this situation I do not <em>need</em> to inline this function. But <em>should</em> I? I will probably never notice any performance difference because I inlined just this one function. But I am trying to figure out if I should make this my general practice in all similar situations. If I inline short functions that are frequently called more aggressively I may see a performance improvement. (My runtime environment is a low power 16bit RISC MCU – that's probably an important detail.)</p>
  
  <p>The reason for asking is this is because there seems to be a disagreement among programmers about this. Is it <em>bad etiquette</em> for some reason to inline functions across translation units (no matter how you do it), and if so, why?</p>
  
  <h1>Assuming I do inline functions across translation units, what's the least detestable or most acceptable way?</h1>
  
  <p>Putting <code>static</code> in a header seems to work well and may be the most portable way to do it. This was pointed out by <a href="https://stackoverflow.com/users/97248/pts">pts</a> in the comments and by and <a href="https://stackoverflow.com/a/25419240/2344440">buzz</a> in the answers. On the surface it seems like I am using <code>static</code> to facilitate using something globally – which is nuts! But I suppose I can more correctly think about it like this: every function that <em>inlines</em> this function will have its own static copy as if it were defined in each of the respective C files as <code>static inline</code>. If that understanding is correct then it seems like the behavior would always be predictable – the linker would have to give me notice if there are two functions with the same name in a translation unit.</p>
  
  <p>I am not sure how I feel about declaring a functions via <code>extern</code> in a header. The wording in 6.7.4 is that external definition in another translation unit is “not forbidden”.</p>