+ 9

What is an inline function?

And what is their purpose? :/ Difference ?

27th Nov 2016, 8:25 PM
LyannaM
LyannaM - avatar
5 Respuestas
+ 8
thankss)
29th Nov 2016, 4:14 AM
LyannaM
LyannaM - avatar
+ 6
When a normal function is called, the program execution is transferred to that function and returns to the main function after the completion of its execution. When a function is made inline, instead to transferring the execution flow to that function, the program codes of that function are expanded in place there, whenever the function is called, its like copying and pasting the function codes to the place where the function is called.
28th Nov 2016, 5:33 PM
Saumya
Saumya - avatar
+ 5
Whenever we declare a function as inline, we send a hint to the compiler that this function will contain very few lines. The compiler then has the option to replace these lines of code from the function at every place wherever this function is called. That is, the calls to the inline function within the program will be replaced by the definition of the function. Therefore, during execution no function call is actually made. Thus no stack access is required as in the case of a normal function call. Stack is accessed during a function call to store the location of the code where the execution must return to upon completion of the function. This access of stack done twice for each function call costs in time. Hence, with inline functions, coding time is saved without any cost of execution time. One point to consider is that- Declaring a function inline does not guarantee that the compiler will replace the function call with its definition in the program. This is a choice made by the compiler. It may or may not make the function inline. The decision may also depend upon the optimisation level set for the compiler. In conclusion, inline function saves the programmer the coding time and also ensures that the execution of the program is fast, as the definition of the function is replaced at each place where the function is called.
28th Nov 2016, 7:27 PM
Navjot Singh Cheema
0
"The inline functions are a C++ enhancement feature to increase the execution time of a program. Functions can be instructed to compiler to make them inline so that compiler can replace those function definition wherever those are being called."
27th Nov 2016, 10:36 PM
Hazel "Joey" Pickett
Hazel "Joey" Pickett - avatar
0
inline function is used for faster execution of program , they replace the function with its definition
2nd Jan 2017, 4:20 PM
likitha
likitha - avatar