I recently thought of this case:
int f()
{
return f();
}
int main(void)
{
f();
return 0;
}
which is definitely a program crash. But my question is: why is this not the same as an infinite loop? In the case of a recursive call on the return line, the compiler can understand that there is no need to store any information of the calling function, since the return point to the called function is the same as the calling one. Now, in this case, I agree that the compiler should store information about functions that invoke calls on the stack:
int f()
{
int x = f();
return x;
}
int main(void)
{
f();
return 0;
}
Of course, I missed something, I would be grateful if anyone would explain this to me. Relationship
source
share