[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-devel
Subject:    Re: offtopic: Re: recursion, stacksize & linux
From:       Michael Matz <matzmich () cs ! tu-berlin ! de>
Date:       2000-12-12 7:59:06
[Download RAW message or body]

Hi,

On Mon, 11 Dec 2000, Doug Welzel wrote:

> After reading up on this some more I think my original statement may be
> incorrect.  It seems like compilers don't actually convert tail recursive
> calls to loops, but just optimize them by doing things like not saving the
> stack frame so you don't have the performance impact of recursion.

No, your initial statement was correct. Even gcc optimizes tail recursion
(version 2.95.2 has some limitations) to loops, and sibling calls to
jumps (only in newer versions).

E.g. this function is fully optimized to a loop:
int f(int i, int j)
{
  if (!j) return i;
  else return f(i+1,j-1);
}


Ciao,
Michael.

 
>> Visit http://master.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic