[gclist] tail recursion requires gc
Fergus Henderson
fjh@cs.mu.OZ.AU
Thu, 8 Aug 1996 05:40:39 +1000 (EST)
William D Clinger, you wrote:
>
> You can't reasonably expect an implementation to be properly
> tail recursive unless it includes a garbage collector, so
> that the compiler can use heap allocation instead of stack
> allocation whenever stack allocation would interfere with
> tail recursion.
[...]
> So don't expect gcc or any other C compiler to provide fully
> general tail recursion any time soon. That won't happen
> until gc becomes a de facto standard part of C.
Nevertheless, it might still be useful if gcc and other C compilers provided
more general tail recursion optimization than they currently do
(even if it's not _fully_ general). If, for example, C compilers
optimized all tail calls in non-elipsis (`...') functions that
don't take the address of any local variables, then compilers
generating C could arrange to generate such code, and use heap
allocation rather than taking the address of local variables.
(Don't expect more general tail recursion for gcc any time soon, but
only because gcc is big and complex and that sort of tail recursion
optimization wasn't designed in, and hence the job is difficult.
Anyone done it for lcc? ;-)
--
Fergus Henderson <fjh@cs.mu.oz.au> | "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh> | of excellence is a lethal habit"
PGP: finger fjh@128.250.37.3 | -- the last words of T. S. Garp.