开发者

Can I force the compiler not to optimize tail-recursion?

开发者 https://www.devze.com 2023-04-02 18:25 出处:网络
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

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

精彩评论

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