What happens with an extern inline function?

c, compiler-construction, header, inline, linker

Solution

Having added the `inline` to the function definition in the `.c` file is just superfluous.

Your compilation unit of the `.c` file sees an `extern` declaration (without `inline`) and an `inline` definition. Thus it emits the symbol for the function in the object file.

All other compilation units only see an `extern` declaration, and so they can use the function without problems, if you link your final executable with the other `.o` file.

In fact, you just have it the wrong way around. This feature is meant to be used that you have the `inline` defintion in the `.h` file, visible to everybody. This definition of the function only acts as a declaration of the symbol, just as `extern` would, but doesn't define it.

An `extern` declaration in just one `.c` file (compilation unit) then ensures such that the symbol is defined, there.

The terminology is a bit confusing, the `inline` definition acting as declaration of the symbol, and the `extern` declaration acting as definition of it

Problem

What happens if I define the function in my .h file as ``` extern int returnaint(void); ``` define it in the related .c file as ``` inline int returnaint(void) { return 1; } ``` and include the header in another .c file and use the function? When I compile the things seperatly, creating a object file for each .c file and then link them, is the inlined function included, or what happens? I know the compiler can ignore `inline`, but what if it does not ignore it in this case?

Original source

Related problems