This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Annoying warning
- To: pedwards at ball dot com (Edwards, Phil)
- Subject: Re: Annoying warning
- From: Joe Buck <jbuck at Synopsys dot COM>
- Date: Sun, 11 Apr 99 18:20:02 PDT
- Cc: egcs at egcs dot cygnus dot com, carlo at runaway dot xs4all dot 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);
}
------------------------