A
A
Anton2012-10-09 16:36:03
C++ / C#
Anton, 2012-10-09 16:36:03

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

3 answer(s)
D
deleted-mifki, 2012-10-09
@deleted-mifki

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.

S
santeri, 2012-10-09
@santeri

try to diff by gcc -S from each option

M
MikhailEdoshin, 2012-10-09
@MikhailEdoshin

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 inlinethe function will (probably) be deployed in inlinethe 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 externfunction. 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 inlineplus adding a non-staticexport 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 question

Ask a Question

731 491 924 answers to any question