Summary of the semantics of inline in C and C++
Here is sample code that illustrates how it works.<p>The approach to using inline functions in C is a bit counterintuitive. Here is how you might define a normal function in C:<p><pre><code>    &#x2F;&#x2F; file.h
    int add_one(int x);

    &#x2F;&#x2F; file.c
    #include &quot;file.h&quot;
    int add_one(int x) {
        return x + 1;
    }
</code></pre>
Here is how you might define it inline:<p><pre><code>    &#x2F;&#x2F; file.h
    inline int add_one(int x) {
        return x + 1;
    }

    &#x2F;&#x2F; file.c
    #include &quot;file.h&quot;
    int add_one(int x);
</code></pre>
Seems backwards to have a definition in the header and prototype in the implementation file, but because the prototype is &quot;extern&quot; (which is default, and can be omitted), and because the definition + declaration <i>merge</i> in certain ways (extern + inline = extern inline), you end up with an &quot;extern inline&quot; definition which means &quot;emit the code in this translation unit, please.&quot; If LLVM&#x27;s behavior is counterintuitive, it&#x27;s probably because it&#x27;s there to support counterintuitive parts of the C language.<p>This frees you from making decisions in a sense, because the compiler can decide whether to use the inline or extern definition at any given call site. Again, the syntax for it is counterintuitive.<p>The other way is:<p><pre><code>    &#x2F;&#x2F; file.h
    static inline int add_one(int x) {
        return x + 1;
    }
</code></pre>
This may give you multiple copies of the code (emitted in potentially any translation unit it appears in), but it&#x27;s less typing.<p>Omitting any discussion about C extensions here.