Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What happens if we make recursive functions as inline?

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?

like image 752
gst Avatar asked Apr 09 '13 18:04

gst


People also ask

What happens when recursive functions are declared inline?

Recursive function declared as inline creates the burden on the compilers execution.

Can a recursive function made inline justify your answer?

When a function is recursive, it cannot be inlined. A function containing static variables cannot be made an inline function.

Do inline functions improve performance What happens when recursion functions declared as inline?

Inline functions behave like macros. When an inline function gets called, instead of transferring the control to the function, the call gets substituted with the function code. Thus this saves time and improves performance.

Can a inline function have a recursive nature?

C++ Inline functions cannot work if the function defined is recursive in nature.


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.
like image 89
Eric Miller Avatar answered Oct 21 '22 02:10

Eric Miller


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.

like image 34
Alexey Frunze Avatar answered Oct 21 '22 03:10

Alexey Frunze