Reputation: 509
I am writing a device driver. I have a questions to ask:
Will it be correct to have inline function declared in .c file?
I am speaking with respect to device driver meant for the linux kernel. I have a function, which is quite short in terms of function body and it is exported from one module to another. Do you think, I can declare it as an inline in the .c file or I need to move this function declaration along with the EXPORT_SYMBOL line to a .h file just because it is inlined? What is the standard Linux kernel practice?
For ex -> something like this?
inline void hello_world( )
{............
return;
}
EXPORT_SYMBOL(hello_world);
Thanks!
Upvotes: 1
Views: 1919
Reputation:
As long as you don't declare a function to be static
, the non-inlined version will be included in the compiled code even if it is declared inline
, precisely to enable code from other compilation units to call the function.
Obviously there will not be any optimisation across function calls when called from outside the compilation unit, unless whole-program optimisation/link-time optimisation is enabled.
Upvotes: 3