int main()
{
int f=fun();
...
}
int fun()
{
return 1;
return 2;
}
Run Code Online (Sandbox Code Playgroud)
在上面的程序中,当从main函数调用一个函数并且该函数包含两个return语句时,
程序控制永远不会到达return 2;,优化编译器会将其删除.
我所知道的唯一一种疯狂的语言return就是Java:
try {
return 1; // this is evaluated
} finally {
return 2; // this is the one actually returned
}
Run Code Online (Sandbox Code Playgroud)