Related articles |
---|
Proper Tail Recursive C++ jerpat@iastate.edu (Jerry) (1997-02-20) |
Re: Proper Tail Recursive C++ sc@informatik.uni-jena.de (Sebastian Schmidt) (1997-02-22) |
Re: Proper Tail Recursive C++ hbaker@netcom.com (1997-02-22) |
Re: Proper Tail Recursive C++ will@ccs.neu.edu (William D Clinger) (1997-02-23) |
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) |
[6 later articles] |
From: | fjh@mundook.cs.mu.OZ.AU (Fergus Henderson) |
Newsgroups: | comp.compilers |
Date: | 23 Feb 1997 22:36:59 -0500 |
Organization: | Comp Sci, University of Melbourne |
References: | 97-02-111 97-02-131 |
Keywords: | C++, optimize |
"Jerry" <jerpat@iastate.edu> wrote:
>> Does anybody know if there exists a C++ compiler that is properly tail
>> recursive? Please tell me where and how I could get my hands on one.
hbaker@netcom.com (Henry Baker) writes:
>There's a bit of a problem defining exactly what you mean by 'properly
>tail recursive C++'. If local storage is allocated in the stack frame
>and is still 'live' at the time of the tail-call, then you can't just
>'re-use' the stack frame.
Furthermore, a C++ compiler pretty much has to assume that any local
variable whose address is taken and passed to a function defined in a
different translation unit is live. Similarly any local variable
which is passed by reference to such a function must also be assumed
live. Furthermore, any local variable with a non-trivial destructor
is live -- C++ does not give compilers the freedom to invoke the
variable's destructor before the tail-recursive call.
>In the particular case where no storage is 'live' at the time of the
>tail call, then I've been told that some versions of GNU may do the
>right thing.
GNU C++ will do it only if a function has no local variables, and only
if there is an explicit tail-recursive `return' statement (a
tail-recursive void-valued function won't be optimized, unless you use
the GNU extension allowing `return' statements in void-valued
functions).
--
Fergus Henderson <fjh@cs.mu.oz.au>
WWW: <http://www.cs.mu.oz.au/~fjh>
PGP: finger fjh@128.250.37.3
--
Return to the
comp.compilers page.
Search the
comp.compilers archives again.