Re: Can we make recursive funcions "Inline" ?
- From: "Carl Daniel [VC++ MVP]" <cpdaniel_remove_this_and_nospam@xxxxxxxxxxxxxxx>
- Date: Wed, 26 Aug 2009 06:41:33 -0700
Ulrich Eckhardt wrote:
Sachin wrote:
Inline is sometimes to used for optimizing a proecss.
Can we make recursive functions inline and what will be its behavior
, what are possibilities that compiler will create inline definition
i mean does compiler treat it any special way ?
The only guaranteed behaviour of 'inline' is that multiple
definitions in different translation units don't cause errors.
Further, it suggests to the compiler that it should paste the
generated code, i.e. elide any function call overhead. This must not
change the semantics though. Actually, if the result is not
distinguishable, the compiler can do what it wants, like inlining
code at will. Modern compilers do exactly that, they treat 'inline'
as just a suggestion.
As far as recursive functions are concerned, you can not include its
code as part of its code, so no actual inlining can take place,
regardless of the presence of the 'inline' keyword.
Actually, some compilers, including VC++, I think, will inline recursive
functions by unrolling the recursion to a certain depth and then using a
call if the recursion goes deeper at runtime. There are also many recusive
functions that are "tail recursive", and a compiler can inline such
functions by converting the recursion into a simple iteration. I'm fairly
certian that VC++ does this optimization as well.
-cd
.
- References:
- Can we make recursive funcions "Inline" ?
- From: Sachin
- Re: Can we make recursive funcions "Inline" ?
- From: Ulrich Eckhardt
- Can we make recursive funcions "Inline" ?
- Prev by Date: Re: Can we make recursive funcions "Inline" ?
- Next by Date: ParseDisplayName problem.
- Previous by thread: Re: Can we make recursive funcions "Inline" ?
- Next by thread: ParseDisplayName problem.
- Index(es):
Relevant Pages
|