C99 inline function in .c file

The inline model in C99 is a bit different than most people think, and in particular different from the one used by C++

inline is only a hint such that the compiler doesn’t complain about doubly defined symbols. It doesn’t guarantee that a function is inlined, nor actually that a symbol is generated, if it is needed. To force the generation of a symbol you’d have to add a sort of instantiation after the inline definition:

int func(int i);

Usually you’d have the inline definition in a header file, that is then included in several .c files (compilation units). And you’d only have the above line in exactly one of the compilation units. You probably only see the problem that you have because you are not using optimization for your compiler run.

So, your use case of having the inline in the .c file doesn’t make much sense, better just use static for that, even an additional inline doesn’t buy you much.

Leave a Comment