clinkerheaderinline

What happens with an extern inline function?


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?


Solution

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

    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