Below is a snippet that gets programmatically generated for a toy programming language, actual code is different but following shows what it does when executed,
class Base{ };
Base b;
class Derived{
int fibo(int i){
if(i SMALLER 2)
return 1;
else
return (Derived)b.fibo(i-1) + (Derived)b.fibo(i-2);
}
};
//then somewhere in main
b = new Derived();
int i = (Derived)b.fibo(10);
My question is will GCC consider this for tail call elimination?
EDIT: Turns out my my view of TOC is a bit flawed, so in a different case a different function with a single return positioned at the tail, would that be considered for optimization? The reason I ask is that there bunch of scheme to c compilers and AFAIK scheme mandates TOC so there must be a way to force this?