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

Richard A. O'Keefe ok@cs.rmit.edu.au
Wed, 7 Aug 1996 17:05:52 +1000 (EST)


    Fergus Henderson wrote, about tail-call optimisation in C:

	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.

If he hadn't said it, I was going to, but there is another case:
when the call passes the address of a local object.  Again, it is
easy for a compiler to detect this and generate a normal call.

I note that the SPARCompiler C 4.0 compiler claims to do "tail call
optimisation", and a small test program shows that
 - it turns self-tail-calls into jumps
 - it turns nonself-tail-calls into "call" instructions annotated with
   "! (tail call)", but the return machinery is replaced by code that
   certainly doesn't execute a return, whatever else it does.

SPARCompiler C++ 4.0 is also supposed to support tail call optimisation.