6.8.5.6
An iteration statement whose controlling expression is not a constant expression,
that performs no input/output operations, does not access volatile objects, and
performs no synchronization or atomic operations in its body, controlling
expression, or (in the case of a for statement) its expression-3, may be assumed
by the implementation to terminate.
如果满足上述条件,编译器就准备终止循环。真的吗? 如果是的话,我试图模拟这种场景但没有成功。 我试过了,
int main()
{
// Some statements...
{
int a = 0;
int b = 100;
int i=0;
while(++i>=0)
{
a = b;
}
}
// Some statements...
return 0;
}
谁能帮我模拟这个场景。
谢谢
最佳答案
嗯,编译器可以假设那里的任何东西。整数溢出是未定义的行为。如果您编写了 while (i==0)
6.8.5.6 将适用。
关于c - 编译器何时可以自由终止循环?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18865469/