Answer the question
In order to leave comments, you need to log in
inline function in C
Good day ...
Can anyone tell me how things are with inline functions in C?
I am making a shared library, while inline functions are used both inside the library and outside.
Now all my inline functions are defined in .h files, and marked as extern inline, while they are exported from the library. If you remove extern from the description, then when you try to call a function from inside the library, a link error occurs.
I want to understand if these functions are actually inlined by the compiler or not...
Answer the question
In order to leave comments, you need to log in
If you are friends with English, then it is described in detail at gcc.gnu.org/onlinedocs/gcc/Inline.html . It's cunning in places, so it's hard to help without specific code.
You write that the function is defined in the header file - do you mean that the entire code of the function is there or just the declaration (that is, it is declared and not defined)? It seems to me that it is only declared, otherwise you would most likely have duplicate characters when linking.
In general, extern inline
the function will (probably) be deployed in inline
the compilation unit where it is defined, and the symbol of the same name will stick out of the resulting object. All other compilation units will use it as a normal extern
function. There is a little discussion on SO .
If you want to expand it in all compilation units, then you can, following the example of C ++, describe the function completely in the header file as static inline
plus adding a non-static
export wrapper. (Or, before compiling, merge all the files into one - it will probably be even easier this way.)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question