[gclist] tail-calls in C/C++

Henry G. Baker hbaker@netcom.com
Tue, 6 Aug 1996 09:10:48 -0700 (PDT)


> |   From: Greg Morrisett <jgm@CS.Cornell.EDU>
> |   Why hasn't someone hacked gcc to do full tail-call elimination?
> |   With the Boehm-Weiser collector, this is really the only thing
> |   that's keeping me from generating very good C code from ML and
> |   Scheme.  
> 
> I too would like to see this, but in general it would have to be
> enabled by a command-line option to the compiler because it
> effectively violates C semantics.
> 
> The problem is the folloowing:
[snip]

Aside from this problem, there is the even more obvious problem of
taking a pointer to a local variable and storing it into a global
variable.  Thus, even if the C function has _no arguments_ and _no
returned values_, it can still allocate storage that _must be there_
until the C function 'would have' returned.  You can be a bit more
clever about where this storage is allocated -- i.e., perhaps using
_two_ stacks -- but the compiler complexity required to understand and
implement this tail recursion optimization _properly_ is quite high.

-- 
Henry Baker
www/ftp directory:
ftp.netcom.com:/pub/hb/hbaker/home.html