Re: Can we make recursive funcions "Inline" ?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



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


.



Relevant Pages

  • Re: Can we make recursive funcions "Inline" ?
    ... Can we make recursive functions inline and what will be its behavior, ... what are possibilities that compiler will create inline definition i mean ... As far as recursive functions are concerned, you can not include its code as ...
    (microsoft.public.vc.language)
  • Re: intercepting inline member functions of a class
    ... They are easy to intercept under *some*, ... If the compiler did inline them, then you can't intercept calls to ... In order to understand recursion you must first understand recursion. ...
    (comp.os.linux.development.system)
  • Re: made it to page 4 of gforth tutorial
    ... support recursion other than tail recursion, ... Neither standard specifies (or ever could ... That's solely up to the compiler vendor and the end ... specifics of the target, I'm going to pretend that I can do anything I ...
    (comp.lang.forth)
  • Re: made it to page 4 of gforth tutorial
    ... support recursion other than tail recursion, ... follow the C standard. ... have trouble calling that a C compiler. ... fully support recursion. ...
    (comp.lang.forth)
  • Re: RAD Studio Roadmap Updated
    ... Strict private and strict protected provide a means for the compiler ... It will comply according to the specification (of the inline ... the exposure of the implementation details is CRITICAL ...
    (borland.public.delphi.non-technical)