Re: Proper Tail Recursive C++

fjh@murlibobo.cs.mu.OZ.AU (Fergus Henderson)
13 Mar 1997 23:44:13 -0500

          From comp.compilers

Related articles
[6 earlier articles]
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 C++ njl@cyberpass.net (1997-03-21)
Re: Proper Tail Recursive C++ erik.schnetter@student.uni-tuebingen.de (1997-03-21)
| List of all articles for this month |

From: fjh@murlibobo.cs.mu.OZ.AU (Fergus Henderson)
Newsgroups: comp.compilers
Date: 13 Mar 1997 23:44:13 -0500
Organization: Comp Sci, University of Melbourne
References: 97-02-111 97-02-131 97-02-141 97-03-042
Keywords: C++, optimize

njl@cyberpass.net (Nathan Loofbourrow) writes:


>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
> }
>
>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 :-)


I'm sure the reason that it crashes is not that g++ generates
incorrect code, but rather that it just runs out of stack space.
(William Clinger's code had the above function recursively invoking
itself a million times.)


I think it is a real pity that Unix systems don't bother to give a better
error message for stack overflow than "segmentation violation".


--
Fergus Henderson <fjh@cs.mu.oz.au>
WWW: <http://www.cs.mu.oz.au/~fjh>
PGP: finger fjh@128.250.37.3
--


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.