From mboxrd@z Thu Jan 1 00:00:00 1970 From: Joe Buck To: pedwards@ball.com (Edwards, Phil) Cc: egcs@egcs.cygnus.com, carlo@runaway.xs4all.nl Subject: Re: Annoying warning Date: Sun, 11 Apr 1999 18:21:00 -0000 Message-id: <199904120120.SAA16476@atrus.synopsys.com> References: X-SW-Source: 1999-04/msg00392.html > 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); } ------------------------ From mboxrd@z Thu Jan 1 00:00:00 1970 From: Joe Buck To: pedwards@ball.com (Edwards, Phil) Cc: egcs@egcs.cygnus.com, carlo@runaway.xs4all.nl Subject: Re: Annoying warning Date: Fri, 30 Apr 1999 23:15:00 -0000 Message-ID: <199904120120.SAA16476@atrus.synopsys.com> References: X-SW-Source: 1999-04n/msg00395.html Message-ID: <19990430231500.6I4jPJu3SEPYm8vFJA_aztdkSB-34GEmWa23zWLCemA@z> > 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); } ------------------------