c - 编译器何时可以自由终止循环?

标签 c

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/

相关文章:

无法使用 Arduino Uno 使用 RF 433 MHz 发射器发送消息

c - 释放指针会释放它引用的内存吗?

c - 如何在从终端执行 C 程序的同时运行终端命令

c - IPC消息队列。 msgrcv 系统调用。系统五、如何跳出循环

c - 将包含 N 个十进制数字的 uint64_t 数据分成两个 uint32_t 并修剪 C 中的输出

c - scanf() 中的 %*c - 这是什么意思?

c++ - 关于C++中float数据类型声明的困惑

c++ - 生成的代码中带有新行的 C 宏

c - 用C读取文件

c - 尝试调用全局 `print'(零值)