MFH*_*MFH 6 c++ recursion static-initialization c++11
是由标准定义的以下间接递归的结果还是未定义的行为?
auto abc() -> int ;
auto xyz() -> int {
static int instance = 3 + abc();
return instance;
}
auto abc() -> int {
static int instance = 2 + xyz();
return instance;
}
int main() {
int tmp = xyz();//or abc();
}
Run Code Online (Sandbox Code Playgroud)
在VS2012中,tmp是5,但我不确定这是否由标准保证.
dyp*_*dyp 10
这是未定义的行为.
[statement.decl/4
如果控件在初始化变量时以递归方式重新输入声明,则行为未定义.[ 例如:
Run Code Online (Sandbox Code Playgroud)int foo(int i) { static int s = foo(2*i); // recursive call - undefined return i+1; }- 结束例子 ]