+ 1
so if I'm trying to make a function as an inline function, how would i know if the compiler called the function or otherwise?
a question about inline functions.
17 ответов
+ 2
محمد عريف
Check out the answer to this SO question :
https://stackoverflow.com/questions/10631283/how-will-i-know-whether-inline-function-is-actually-replaced-at-the-place-where
+ 3
According to the first answer in that question, analysing the associated assembly code is one way to find out.
+ 3
Use of the gcc parameter -Winline to warn about inlining of functions seems to be another way. That's of course if you are using the gcc compiler.
+ 2
Ah OK محمد عريف
That's not called calling the function. The function is called during execution. The compiler will decide to make the function inline or not (e.g. for the cases that you mentioned).
+ 2
I don't exactly know how you can tell if the compiler decided to inline a function محمد عريف .
Perhaps the compilation logs will show that evidence.
+ 2
Have a look at the following link as well:
https://en.m.wikipedia.org/wiki/Inline_function
+ 2
Cases where a compiler will not inline a function include cases where the function includes: nested functions, external or computed gotos, recursion etc. But this is also compiler dependent.
+ 2
Thought.........can't you just check the size of the executable with and without the "inline" specifier and compare them? (might have a go at that myself actually)
+ 2
محمد عريف
You're welcome.
+ 1
The compiler does not call the function.
+ 1
Sonic ah i thought the compiler would call the function if its too huge to be inline. for example if it got loops or otherwise
+ 1
so my point of this question is if there's other causes than it being:
loops / recursive function
+ 1
Sonic Exactly, now how would i know the compilers decision? (beside the cases i've mentioned)
+ 1
Sonic that's what i wondered as well.. anyway thanks for your time 😁
+ 1
rodwynnejones clever idea, ill consider using that if i got no answer to my question 😁
+ 1
Sonic that's an answer that did satisfy my need. thanks for your effort.
- 3
is thou vegan?