Can anyone explain inline functions in c++ | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Can anyone explain inline functions in c++

7th Aug 2017, 3:14 AM
Ashutosh Srivastava
Ashutosh Srivastava - avatar
7 Answers
+ 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.
7th Aug 2017, 3:54 AM
aklex
aklex - avatar
+ 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.
7th Aug 2017, 9:49 PM
Katie (Ctrl-Alt-Cuteness)
Katie (Ctrl-Alt-Cuteness) - avatar
0
Kya karega seekhke 😂😂
7th Aug 2017, 4:46 PM
Ramprakash Ganesan
Ramprakash Ganesan - avatar
0
abey college walo ne pareshan kar rakha hain yar.
7th Aug 2017, 4:57 PM
Ashutosh Srivastava
Ashutosh Srivastava - avatar
0
inline function Shayad compilation time speed up karta hai function definition function calling ke pass bulake
7th Aug 2017, 4:59 PM
Ramprakash Ganesan
Ramprakash Ganesan - avatar
0
sab padh ke baitha hai 😂😂
7th Aug 2017, 5:00 PM
Ashutosh Srivastava
Ashutosh Srivastava - avatar
0
Bhai school mein sikhaya tha C++ mein Python Java mein nahi hai kya ?
7th Aug 2017, 5:02 PM
Ramprakash Ganesan
Ramprakash Ganesan - avatar