Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You have things exactly the wrong way around from the way you need them. In the header, you should use:</p> <pre><code>inline void SPFD54124B_write_cmd(uint16_t command) { spi_write(command, CMD_WIDTH); } </code></pre> <p>In the translation units that include this header, this will create an inline function with external linkage. In exactly <em>one</em> of these translation units you should also place the declaration:</p> <pre><code>extern void SPFD54124B_write_cmd(uint16_t); </code></pre> <p>This (together with the <code>inline</code> definition from the header) will create an <em>external definition</em> of the function. The other files that include the header but do not include the <code>extern</code> declaration will create an <em>inline definition</em> of the function: a definition only available in that translation unit, but that does not forbid an external definition elsewhere.</p> <p>In total you will have one external definition of the function, and each file that includes the header will also have a non-external definition available; the compiler can use either. Conceptually there is still just one function called <code>SPFD54124B_write_cmd</code> in the complete program - for example if you take the address of the function in multiple translation units you should get the same value.</p> <p>As an alternative, you can put this in the header:</p> <pre><code>static inline void SPFD54124B_write_cmd(uint16_t command) { spi_write(command, CMD_WIDTH); } </code></pre> <p>and use no <code>extern</code> declaration at all; this will create an inline function with internal linkage in each file that includes the header. There will be no external definition of the function at all, and conceptually each translation unit that includes the header has its own independent copy of the function.</p> <hr> <p>(It should be noted for posterity that GCC's current default mode is "gnu89", which does <em>not</em> implement C99 semantics for <code>inline</code>)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload