0
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;
}

谁能帮我模拟这种情况。

谢谢,

4

2 回答 2

0

尝试使用-O2、-O3等编译器优化级别。它应该可以帮助你:)

笔记:

对于 GCC 系列编译器,请尝试-O2 或 -O3

对于 MSVC,请尝试/O2 或 /O3

于 2013-09-18T06:47:38.857 回答
0

好吧,编译器可以在那里假设任何东西。整数溢出是未定义的行为。如果你写while (i==0)了 6.8.5.6 将适用。

于 2013-09-18T06:44:37.467 回答