If I write a function as follows
int sum(int i)
{
if(!i)
return 0;
return sum(i--) + i; //this line
}
How does the compiler represent the return statement in terms of three address code/intermediate code? Does
1) return i-- + sum(i) differ from 2) return sum(i) + i--?
My interpretation is that in the first case if i is added and then sum is recursively called with i-1 as parameter and in the other case sum is called with i as parameter and i-1 is added to it. Is that right? Can someone explain what happens at the compiler level?
Also what if modify 1) and 2) as
1)return i + sum(i--) and 2) return sum(i--) + i
what happens in the recursive sense? It will be an infinite loop I think but what about the i-- ?