+ 2

What is an inline function?

28th Jan 2017, 2:29 PM
Jatin Unecha
Jatin Unecha - avatar
3 ответов
+ 5
In C++: Inlining prevents overhead from method/function call. Inline methods should be written in class definition (.h file). Only small code methods/functions should be used as inline. Compiler replaces definition of inline methods at compile time with the method code instead of referring to method definition at runtime. Results in faster runtime, but larger compiled code.
28th Jan 2017, 2:41 PM
Jafca
Jafca - avatar
+ 1
In Scala you can write @inline to a function definition. When the program is compiled the function gets removed and the body is copied everywhere it is called. So you have less function calls at runtime. That might speed up your program under certain circumstances.
28th Jan 2017, 10:44 PM
1of3
1of3 - avatar
+ 1
Inline Function (C++) ------------------------ - Commonly used for calculation. - The function call is replaced with the function logic at the time of compilation. - Make execution faster. - Compiled code is relatively bigger. inline int sum (int a=0, int b=0){ return (a+b); } cout<<sum(10,20); => cout<<(10+20); Earlier in C language same can be achieved by using #define preprocessor statement. It is data type independent. On contrary, inline functions are tightly typed.
12th Mar 2017, 3:19 PM
देवेंद्र महाजन (Devender)
देवेंद्र महाजन (Devender) - avatar