开发者

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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜