+ 2
Can anyone explain inline functions in c++
7 ответов
+ 5
For a normal function, the parameters have to be put in registers and/or pushed onto the stack (depending on the calling convention), the return address needs to also be pushed onto the stack, and then the program jumps with a call to the location of where that function is stored in virtual memory. After that, the caller or callee has to clean the stack and the callee has to jump back to the caller function.
This is a lot of work and creates an overhead, especially for functions that are small and called often.
The solution: Inlining. Inlining is when the compiler inserts the function's code itself in every location where it would have been called. This removes the overhead of doing everything I stated above., but also increases the binary size of program.
The compiler can also generate intrinsic functions, which are similar but a little different on how they are implemented.
+ 2
I am going to suppliment the correct answer.
If you use the same in-line function for, let's say, 14 times, that is the function's body 14 times in the code. If that function is large, then you have just increased your resulting executable's file size by a lot.
EDIT (2017/08/25): An inline function cannot use recursion on itself without expanding what its own code is into itself indefinitely.
0
Kya karega seekhke 😂😂
0
abey college walo ne pareshan kar rakha hain yar.
0
inline function Shayad compilation time speed up karta hai
function definition function calling ke pass bulake
0
sab padh ke baitha hai 😂😂
0
Bhai school mein sikhaya tha
C++ mein
Python Java mein nahi hai kya ?