编译器是否有可能在这种情况下识别尾递归?
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... */
}
}
在return;
之后放置一个f(2);
会帮助编译器将其识别为尾递归情况吗?
答案 0 :(得分:0)
识别尾调用优化机会的编译器在该特定用例中识别它应该没有问题。