This is the mail archive of the libstdc++@sourceware.cygnus.com mailing list for the libstdc++ project. See the libstdc++ home page for more information.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

[cygnus.egcs] Re: Annoying warning


------- Start of forwarded message -------
From: jbuck@Synopsys.COM (Joe Buck)
Newsgroups: cygnus.egcs
Subject: Re: Annoying warning
Date: 11 Apr 1999 18:22:29 -0700
Organization: Cygnus Solutions news/mail gateway
Message-ID: <199904120120.SAA16476.cygnus.egcs@atrus.synopsys.com>
References: <B7A6155A71B6D211BB2D0008C7B250B70905CA@daytonmsg.ball.com>
To: pedwards@ball.com (Edwards, Phil)
Cc: egcs@egcs.cygnus.com, carlo@runaway.xs4all.nl


> I mentioned this to the libstdc++-v3 list some time back.  The solution then
> was to simply remove the 'inline' since (according to the list) the egcs
> optimizer doesn't know how to turn tail recursion into a loop. 

That's incorrect: gcc does know how to eliminate tail recursion and has
for a long time.  RMS put that one in years ago: anyone from MIT, where
Scheme rules, wouldn't tolerate a compiler that can't handle tail recursion.

I just confirmed that gcc/egcs correctly transforms and inlines a
tail-recursive function on the Sparc.

Here's my testcase.
---------------------------------
struct node {
    struct node* next;
    int data;
};

inline int last_node(node* p) {
    if (p->next)
	return last_node(p->next);
    else
	return p->data;
}

int call_last_node(node* p) {
    return last_node(p);
}

------------------------
------- End of forwarded message -------