I have a questions about using inline keyword in C code (C99). I know C99 inline semantics are different than C++ or gnuC inline rules, I have read
http://www.greenend.org.uk/rjk/tech/inline.html
and
but, I just can't get this working.
I have a function definition as below in file1.c
inline myfunc(arguments)
{
}
And this function is called from another function in file2.c
In that file2.c I tried using
extern inline myfunc(arguments);
for this function before it is called from the other function
still I keep getting error - implicit declaration of myfunc
or undefined reference error if I remove the extern inline
Due to my code structure, cannot have the myfunc function definition in a header file nor can have it as static inline, as it has to be called from different compilation units.
What is that I am getting wrong? How to fix it.
After lot of reading about this, trial and error I have found answer to my problem above in a way I was looking for - Inline a C function definition present in a C source file, using C99 rules, without putting it in a header file. I added the attribute always_inline keyword to the function definition and declaration as below and recompiled, it inlines the call to that function. In file file1.c
__attribute__((always_inline)) void myfunc(arguments)
{
//... function definition
}
and in file1.h which has its declaration , I changed it to be as below
__attribute__((always_inline)) void myfunc(arguments);