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? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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.

8th Feb 2020, 10:10 PM
‎محمد عريف‎
‎محمد عريف‎ - avatar
17 Answers
+ 3
According to the first answer in that question, analysing the associated assembly code is one way to find out.
8th Feb 2020, 11:22 PM
Sonic
Sonic - avatar
+ 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.
8th Feb 2020, 11:23 PM
Sonic
Sonic - avatar
+ 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).
8th Feb 2020, 10:17 PM
Sonic
Sonic - avatar
+ 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.
8th Feb 2020, 10:25 PM
Sonic
Sonic - avatar
+ 2
Have a look at the following link as well: https://en.m.wikipedia.org/wiki/Inline_function
8th Feb 2020, 10:25 PM
Sonic
Sonic - avatar
+ 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.
8th Feb 2020, 10:28 PM
Sonic
Sonic - avatar
+ 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)
8th Feb 2020, 10:35 PM
rodwynnejones
rodwynnejones - avatar
+ 2
محمد عريف You're welcome.
8th Feb 2020, 11:26 PM
Sonic
Sonic - avatar
+ 1
The compiler does not call the function.
8th Feb 2020, 10:11 PM
Sonic
Sonic - avatar
+ 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
8th Feb 2020, 10:13 PM
‎محمد عريف‎
‎محمد عريف‎ - avatar
+ 1
so my point of this question is if there's other causes than it being: loops / recursive function
8th Feb 2020, 10:14 PM
‎محمد عريف‎
‎محمد عريف‎ - avatar
+ 1
Sonic Exactly, now how would i know the compilers decision? (beside the cases i've mentioned)
8th Feb 2020, 10:19 PM
‎محمد عريف‎
‎محمد عريف‎ - avatar
+ 1
Sonic that's what i wondered as well.. anyway thanks for your time 😁
8th Feb 2020, 10:27 PM
‎محمد عريف‎
‎محمد عريف‎ - avatar
+ 1
rodwynnejones clever idea, ill consider using that if i got no answer to my question 😁
8th Feb 2020, 10:37 PM
‎محمد عريف‎
‎محمد عريف‎ - avatar
+ 1
Sonic that's an answer that did satisfy my need. thanks for your effort.
8th Feb 2020, 11:23 PM
‎محمد عريف‎
‎محمد عريف‎ - avatar
- 3
is thou vegan?
10th Feb 2020, 7:56 PM
Ranvir
Ranvir - avatar