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?
Asked
Active
Viewed 5,344 times
9
-
3Possible duplicate of http://stackoverflow.com/questions/190232/can-a-recursive-function-be-inline – SecurityMatt Apr 09 '13 at 18:08
-
1@SecurityMatt may be the next time I will be more careful. Thankyou. – gst Apr 09 '13 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 Apr 09 '13 at 18:18
-
1@VenkateshKuppan I putted a link below to Alexey Fruze's Answer, you may like to read over there. – Grijesh Chauhan Apr 09 '13 at 18:27
2 Answers
5
"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.

Eric Miller
- 1,944
- 16
- 12
-
1Just because it is recursive, doesn't mean your compiler won't inline it: http://msdn.microsoft.com/en-us/library/69hzy453(v=vs.80).aspx – SecurityMatt Apr 09 '13 at 18:44
-
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. – Grijesh Chauhan Apr 09 '13 at 18:50
5
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.

Alexey Frunze
- 61,140
- 12
- 83
- 180
-
1[Yes few level possible in Microsoft compiler](http://wiki.answers.com/Q/What_is_inline_function_in_C_Can_you_make_inline_function_recursive_or_not_If_make_can_complier_will_compile_that_code) Just liked to share link with you – Grijesh Chauhan Apr 09 '13 at 18:20