2 ms·
Infinite loop with a constant expression is defined behavior. for (;;) { }; cannot be assumed to have finite number of executions. Therefore, it cannot be opti
by AstralStorm 4y ago
Infinite loop with a constant expression is defined behavior.
for (;;) { }; cannot be assumed to have finite number of executions.
Therefore, it cannot be optimized away to finite execution.
You're showing potentially infinite loops with non-constant expression as condition.
for (; i != 0; ) {} can be assumed to have finite number of executions and can be optimized unless i is constant expression.
- haberman 4y ago> Infinite loop with a constant expression is defined behavior. Yes, because a constant controlling expression is one of the enumerated exceptions to the rule against infinite loops. > You're showing potentially infinite loops with non-constant expression as condition. "for (int i = 0; i < 1;)" is an infinite loop, full stop. It is not potentially infinite, it is infinite under all possible executions. It is UB because it does not fall under one of the enumerated exceptions where an infinite loop is allowed. I think we are saying the same thing, the only difference is that you seem to be defining "infinite loop" to only include loops with constant controlling expressions, whereas I am defining it to mean "any loop that does not terminate."