Related articles |
---|
[4 earlier articles] |
Re: Proper Tail Recursive C++ fjh@mundook.cs.mu.OZ.AU (1997-02-23) |
Re: Proper Tail Recursive C++ bothner@cygnus.com (1997-02-23) |
Re: Proper Tail Recursive C++ andy@wonderworks.co.uk (Andy Armstrong) (1997-02-27) |
Re: Proper Tail Recursive C++ gary@wheel.tiac.net (1997-03-01) |
Re: Proper Tail Recursive C++ Wilco.Dijkstra@armltd.co.uk (Wilco Dijkstra) (1997-03-01) |
Re: Proper Tail Recursive C++ hbaker@netcom.com (1997-03-05) |
Re: Proper Tail Recursive C++ njl@cyberpass.net (1997-03-09) |
Re: Proper Tail Recursive C++ hbaker@netcom.com (1997-03-13) |
Re: Proper Tail Recursive C++ fjh@murlibobo.cs.mu.OZ.AU (1997-03-13) |
Linking Was: Re: Proper Tail Recursive C++ hrubin@stat.purdue.edu (1997-03-16) |
Re: Proper Tail Recursive C++ ramsdell@linus.mitre.org (1997-03-16) |
Re: Proper Tail Recursive C++ danwang@atomic.CS.Princeton.EDU (1997-03-18) |
Re: Proper Tail Recursive Java robison@kai.com (Arch Robison) (1997-03-18) |
[2 later articles] |
From: | njl@cyberpass.net (Nathan Loofbourrow) |
Newsgroups: | comp.compilers |
Date: | 9 Mar 1997 11:33:14 -0500 |
Organization: | Infonex Internet Services |
References: | 97-02-111 97-02-131 97-02-141 |
Keywords: | C++, optimize |
William D Clinger <will@ccs.neu.edu> writes:
int f (int n) {
int A[1000];
A[0] = n;
A[999] = n;
return g (A); // tail-recursive call to g
}
[...]
It is extremely unlikely that any C++ compiler is properly tail
recursive in this sense.
Well, since no one else tried it: g++ compiles this, but the result
crashes. I gather that this is because it assumes that A is dead
before the call to g(). This permits it the luxury of performing the
tail recursion optimization, at the expense of producing code that
doesn't work :-)
Without either global analysis or garbage collection, I don't see any
way for the example to be made to work in C++, since the lifetime of
the automatic variable has to exceed the life of a tail recursion
optimized procedure. One could call this a bug, unless it were
documented as a feature.
nathan
[Tail recursion optimization does indeed seem to be of interest mostly to
users of languages like Scheme that promise garbage collection. -John]
--
Return to the
comp.compilers page.
Search the
comp.compilers archives again.