“I bought this guide a few days ago to prepare for my interview with Oracle. Many of the questions they asked me were from this guide. I found this book absolutely great!”
I think there should not be any problem with this. Certainly function call is replaced by the function body however this does not mean that function itself will be removed from the module. Usually compiler don’t remove such functions/procedures due to the fact that some other module (in project or application) may have call to this “inline” function
Please do share if somebody have different thoughts.
Actually, Syntax wise it is allowed but function will no longer inline function. As the compiler will never know how deep the recursion is at compilation time.
Inline functions are short functions that are not actually called; rather, their code is expanded in line at the point of each invocation.
Both the below codes are same:
inline int max(int a, int b)
{
return a>b ? a : b;
}
int main()
{
cout 20 ? 10 : 20);
cout 88 ? 99 : 88);
return 0;
}
Each time a function is called, a significant amount of overhead is generated by the calling and return mechanism. Typically, arguments are pushed onto the stack and various registers are saved when a function is called, and then restored when the function returns. The trouble is that these instructions take time. However, when a function is expanded in line, none of those operations occur. Although expanding function calls in line can produce faster run times, it can also result in larger code size because of duplicated code. For this reason, it is best to inline only very small functions.
Inline is actually just a request, not a command, to the compiler. The compiler can choose to ignore it. Also, some compilers may not inline all types of functions. For example, it is common for a compiler not to inline a recursive function. If a function cannot be inlined, it will simply be called as a normal function.
So it is not advisable to inline a recursive function.
Depends on the compiler. As shreejc said, inline is a request, which the compiler can ignore, and it is not advisable. However, it is still possible and some compilers may inline, but only the first call, since it can not predict how deep it may go (as Syed Naqvi said).
Inline functions are those functions which have small function body and they do not call other functions from them to do their task.So we cannot use recursive in inline functions.Inline functions are use to increase the execution speed of the program because these functions are not called by the compiler but the whole function body is pasted ,where these functions are called,for function to be an inline is totally depend on the compiler because inline is not acommand to the compiler but it is a request.
Definitely not. An inline function will be replaced by its body. So a recursion does not possible with inline functions.
Inline functions r very small programs,it does not support complex loops,pointers etc.
I think there should not be any problem with this. Certainly function call is replaced by the function body however this does not mean that function itself will be removed from the module. Usually compiler don’t remove such functions/procedures due to the fact that some other module (in project or application) may have call to this “inline” function
Please do share if somebody have different thoughts.
Thanks.
Actually, Syntax wise it is allowed but function will no longer inline function. As the compiler will never know how deep the recursion is at compilation time.
Thanks,
Syed
Inline functions are short functions that are not actually called; rather, their code is expanded in line at the point of each invocation.
Both the below codes are same:
inline int max(int a, int b)
{
return a>b ? a : b;
}
int main()
{
cout 20 ? 10 : 20);
cout 88 ? 99 : 88);
return 0;
}
Each time a function is called, a significant amount of overhead is generated by the calling and return mechanism. Typically, arguments are pushed onto the stack and various registers are saved when a function is called, and then restored when the function returns. The trouble is that these instructions take time. However, when a function is expanded in line, none of those operations occur. Although expanding function calls in line can produce faster run times, it can also result in larger code size because of duplicated code. For this reason, it is best to inline only very small functions.
Inline is actually just a request, not a command, to the compiler. The compiler can choose to ignore it. Also, some compilers may not inline all types of functions. For example, it is common for a compiler not to inline a recursive function. If a function cannot be inlined, it will simply be called as a normal function.
So it is not advisable to inline a recursive function.
Depends on the compiler. As shreejc said, inline is a request, which the compiler can ignore, and it is not advisable. However, it is still possible and some compilers may inline, but only the first call, since it can not predict how deep it may go (as Syed Naqvi said).
Inline functions are those functions which have small function body and they do not call other functions from them to do their task.So we cannot use recursive in inline functions.Inline functions are use to increase the execution speed of the program because these functions are not called by the compiler but the whole function body is pasted ,where these functions are called,for function to be an inline is totally depend on the compiler because inline is not acommand to the compiler but it is a request.
//The following code will work.
//Inline is just a request to the compiler and I don’t think compiler have made this function Inline
#include
using namespace std;
inline int a(int n)
{
if(n==0)
return n;
return n+a(n-1);
}
int main()
{
cout
Leave an Answer/Comment