I have a file funcs.h
where I have the declaration of function:
inline void some_func( void ) __attribute__((always_inline));
Then I have a file funcs.c
where I have the implementation of the function:
inline void some_func( void ) { … }
Then in my main file main.c
I #include
the funcs.h
and try to use some_func()
somewhere in the code. However when I compile my program and look at the binary file, the function appears to be compiled as a regular separate function, and called just like any other regular function, instead of being embedded as inline.
Why is that happening, and is there a way to force actual inlining into this? (Except the option of just using #define
macros instead of functions, of course.)
Put the implementations is the header. If they're not available in the translation unit in which you intend to do the inlining, you'll be out of luck. The linker (well, a traditional linker) can't do anything about that for you.