This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: proper tail recursion for gcc
- To: Joern Rennecke <amylaar at cygnus dot co dot uk>
- Subject: Re: proper tail recursion for gcc
- From: John Vickers <John dot Vickers at pace dot co dot uk>
- Date: Fri, 21 Jul 2000 00:36:02 +0100
- CC: Per Bothner <per at bothner dot com>, Richard Henderson <rth at cygnus dot com>, gcc at gcc dot gnu dot org
- Organization: Pace Micro Technology PLC
- References: <200007202146.WAA07355@phal.cygnus.co.uk>
Joern Rennecke wrote:
>
> > When foo_with_bar returns, it will return to foo's caller, which
> > will pop off b and c. a remains on the stack, but does no harm.
> > When foo's caller returns, a will get popped, just as if a had
> > been alocated with alloca.
Every argument frame written to the stack for a tail call
has to start at the beginning of the argument frame of the caller:
i.e. each tail caller in effect pops it's own arguments before pushing
the tail callee's arguments.
Otherwise tail recursion between two functions with different sized
argument frames would use unbounded memory.
> >
> > This will fail if foo's caller is compiled to not use a frame pointer,
> > since the stack pointer will not be where it expects it.
>
> And even if it has been compiled with a frame pointer, there can
> be a stack overflow if the call is done in a loop with many iterations.
What is this "loop" construct of which you speak ?
Regards,
John.