Can I force the compiler not to optimize tail-recursion?
Imagine thi开发者_Python百科s code:
int foo() {
return foo();
}
The compiler can optimize this. Can I force the compiler to use a new stack frame for foo, instead of using the same stack frame (per case, so disabling optimization completely doesn't count)?
Yes, with -fno-optimize-sibling-calls
option.
In gcc, try either:
- -O0
- -fno-optimize-sibling-calls
精彩评论