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;
}有人能帮我模拟一下这个场景吗。
谢谢,
发布于 2013-09-18 14:44:37
好的,编译器可以在那里假设任何东西。整数溢出是未定义的行为。如果您已经编写了while (i==0) 6.8.5.6,那么它将适用。
发布于 2013-09-18 14:47:39
尝试使用编译器优化级别,如-O2、-O3。它应该对您有所帮助:)
注意:
对于GCC家族的编译器,请尝试使用-O2或-O3
对于MSVC,请试用/O2或/O3
https://stackoverflow.com/questions/18865469
复制相似问题