I have a doubt regarding inline functions. Inline functions will not involve any function calls but just replacement of function definition wherever the call is made to the inline function.Inline functions have type enforcement unlike macros. What will happen if recursive functions are made inline?
- 3Possible duplicate of stackoverflow.com/questions/190232/…SecurityMatt– SecurityMatt2013-04-09 18:08:14 +00:00Commented Apr 9, 2013 at 18:08
- 1@SecurityMatt may be the next time I will be more careful. Thankyou.gst– gst2013-04-09 18:11:05 +00:00Commented Apr 9, 2013 at 18:11
- 1odd answer but: Many compilers can also inline expand some recursive functions; The Microsoft implementation will not inline recursive functions unless they have a #pragma inline depth(n) line that specifies the maximum recusion depth the function will have.Grijesh Chauhan– Grijesh Chauhan2013-04-09 18:18:35 +00:00Commented Apr 9, 2013 at 18:18
- 1@VenkateshKuppan I putted a link below to Alexey Fruze's Answer, you may like to read over there.Grijesh Chauhan– Grijesh Chauhan2013-04-09 18:27:04 +00:00Commented Apr 9, 2013 at 18:27
Add a comment |
2 Answers
"inline" isn't a guarantee, it's a request.
Your recursive inline function won't (typically) be inline.
- As some commenters point out, there are special cases (e.g. using compiler-specific pragmas) in which inlining is possible.
2 Comments
SecurityMatt
Just because it is recursive, doesn't mean your compiler won't inline it: msdn.microsoft.com/en-us/library/69hzy453(v=vs.80).aspx
Grijesh Chauhan
improve your answer, with link given by @SecurityMatt, yes most compilers don't inline recursive functions but some do....read my comment to question also.
inline is merely a suggestion to the compiler and does not guarantee that a function will be inlined.
Obviously, the compiler won't be able to inline a recursive function infinitely. It may not inline it at all or it may inline it just a few levels deep.
1 Comment
Grijesh Chauhan
Yes few level possible in Microsoft compiler Just liked to share link with you