gst
gst

Reputation: 1285

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?

Upvotes: 9

Views: 5506

Answers (2)

Eric Miller
Eric Miller

Reputation: 2031

"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.

Upvotes: 5

Alexey Frunze
Alexey Frunze

Reputation: 62106

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.

Upvotes: 5

Related Questions