+ 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
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