Is while(1); undefined behavior in C?

It is well defined behavior. In C11 a new clause 6.8.5 ad 6 has been added An iteration statement whose controlling expression is not a constant expression,156) 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 … Read more

Strange behavior of Enumerator.MoveNext()

List<T>.GetEnumerator() returns a mutable value type (List<T>.Enumerator). You’re storing that value in the anonymous type. Now, let’s have a look at what this does: while (x.TempList.MoveNext()) { // Ignore this } That’s equivalent to: while (true) { var tmp = x.TempList; var result = tmp.MoveNext(); if (!result) { break; } // Original loop body } … Read more

Are compilers allowed to eliminate infinite loops?

C11 clarifies the answer to this question, in the draft C11 standard section 6.8.5 Iteration statements added the following paragraph: An iteration statement whose controlling expression is not a constant expression,156) 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 … Read more

Prolog successor notation yields incomplete result and infinite loop

If you want to study termination properties in depth, programs using successor-arithmetics are an ideal study object: You know a priori what they should describe, so you can concentrate on the more technical details. You will need to understand several notions. Universal termination The easiest way to explain it, is to consider Goal, false. This … Read more

tech