This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


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

Re: Annoying warning



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

------------------------


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