草庐IT

c++ - 为什么这个循环会产生 "warning: iteration 3u invokes undefined behavior"并输出超过 4 行?

编译:#includeintmain(){for(inti=0;i和gcc产生以下警告:warning:iteration3uinvokesundefinedbehavior[-Waggressive-loop-optimizations]std::cout我知道有符号整数溢出。我无法理解为什么i值会被溢出操作破坏?我已阅读Whydoesintegeroverflowonx86withGCCcauseaninfiniteloop?的答案,但我仍然不清楚为什么会发生这种情况——我知道“未定义”的意思是“任何事情都可能发生”,但是这种特定行为的根本原因是什么?在线:http://ideon