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

Fergus Henderson fjh@cs.mu.OZ.AU
Wed, 7 Aug 1996 04:33:54 +1000 (EST)


Guillermo wrote:
> 
> |   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.

Oh, you mean it breaks some crufty old K&R programs that
aren't standard-conforming anyway?  I don't see that as a big
deal.  An option to turn it off would be good, for backwards
compatibility, but if you break the rules, you shouldn't be
surprised if the compiler breaks your code.

> The problem is the folloowing:
> 
> 	Assume A calls B which in turn tail-calls C
> 	Either B uses ... or no prototype for B is visible at A.
> 
> Thus A can call B with more arguments (and hence locations on the
> stack) than the number expected by B.

For standard-conforming programs, this problem only arises
in the case when B uses `...'.  It's easy enough to not
perform the optimization in that case.

-- 
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.