| Liste des Groupes | Revenir à cl c |
On 11/06/2026 17:34, Janis Papanagnou wrote:On 2026-06-11 08:56, David Brown wrote:>On 10/06/2026 23:47, Keith Thompson wrote:>[...]>
>
#include <stdio.h>
int main(void) {
bool keep_going = true;
while (keep_going) {
keep_going = true;
}
puts("never reached");
}
>
[...]
[...]
>
The loop might originally have contained source code, but become
empty through pre-processing, or from other compiler
transformations (such as the compiler seeing that the "keep_going"
variable is not volatile and its value is never used, so
assignments to it can be elided, or moving other things outside the
loop body).
>
A programmer /could/ write the "keep_going" loop you gave, and
mistakenly believe it to be infinite. But is it likely?
I think we should not make any assumptions about the "creativity" of
a programmer ("C" or else). - Semantics should be well defined, and
then clear to the programmer.
I think the semantics of this "loops can be assumed to terminate" are
clearly defined in the standard. I agree that the details might not
be known to all C programmers, but I think they are only relevant in a
very small number of cases.
Les messages affichés proviennent d'usenet.