简体   繁体   English

复杂的尾递归情况

[英]Complicated tail recursion case

Is it possible for the compiler to recognize tail-recursion in cases such as this? 在这种情况下,编译器是否可以识别尾递归?

void f(int x) {
    if (x == 1) {
        /* do_1... */
    }
    else if (x == 2) {
        /* do_2... */
    }
    else if (x == 3) { // here, we want do_2 and do_3; the order doesn't matter
        /* do_3... */
        f(2); // this should be tail recursive
    }
    else if (x == 4) {
        /* do_4... */
    }
}

Would placing a return; return; after f(2); f(2); help the compiler recognize it as a tail-recursion case? 帮助编译器将其识别为尾递归情况?

识别出尾部调用优化机会的编译器在该特定用例中应该毫不费力地识别出它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM