Gene wrote:
> Indeed the C/C++ compilers I've used lately don't eliminate tail
> recursion.  GCC used to do it, but later versions don't seem to work.
> MS Visual C has never worked.  On  the other hand, all functional
> language compilers are similar in this respect to Scheme. They need to
> be since tail recursion is necessary for iterative computations.
> Examples include all usable implementations of SML, Haskel, Common
> Lisp, Prolog, and others.

VC7.1, with normal Release settings, will do tail end recursion for

// Add by counting on fingers, with opportunity for tail-end recursion
unsigned int AddTer(unsigned int a, unsigned int b)
{
  if(! b)
    return a;
  return AddTer(a+1, b-1);
}

but not for

// Same thing, with no opportunity for tail-end recursion
unsigned int AddNoTer(unsigned int a, unsigned int b)
{
  if(! b)
    return a;
  return a+1+AddNoTer(0, b-1);
}

With normal Debug settings, neither version gets tail-end recursion.

Reply via email to