


The same goes for array bounds, object references etc. When you divide by zero in it, the interpreter double-checks the divisor and prints a nice traceback Python code, on the other hand, is just random binary data at runtime that another code - the interpreter - looks at and determines what to do. the CPU actually attempts it, generates a hardware interrupt which the OS handles and ultimately terminates your process. When you divide by zero in it, it happens Now sit back and remember what C code looks like at runtime. The godbolt implementation of gcc-10.2 also causes a runtime error after some amount of time passes (which is not non-conforming since the loop may be assumed to terminate). If this argument is accepted then any other result is possible, including compilation error.Ĭlang (trunk) does appear to treat it as undefined behaviour, aborting the program when execution reaches the loop. It can be argued that attempting to execute such a loop means the behaviour is undefined, since the standard doesn't have anything to say about what it means for a loop to terminate in this manner (e.g. Or in other words, runtime complexity is not considered part of the program's observable behaviour, unless hanging forever is intentionally signalled by a The purpose of this clause is to allow the optimizer to remove empty loops, without having to prove that the loop would eventually end. On your implementation of course) it may stay in the loop forever and output nothing. So the program may behave as if the loop terminates, i.e. Your program falls into this case, since the loop condition is not a constant expression, as it involves a variable , may be assumed by the implementation to Every loop must either do something or exit, and there's an exception for "intentional" infinite loops such asĪn 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
