Re: Compile time checking of standards conformance

Liste des GroupesRevenir à l c 
Sujet : Re: Compile time checking of standards conformance
De : eesnimi (at) *nospam* osa.pri.ee (Paavo Helde)
Groupes : comp.lang.c comp.lang.c++
Date : 24. May 2024, 16:39:31
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <v2q8r2$2c8vg$1@dont-email.me>
References : 1 2 3
User-Agent : Mozilla Thunderbird
On 23.05.2024 21:13, James Kuyper wrote:
On 5/23/24 02:23, Paavo Helde wrote:
...
There are zillions of ways to write non-conforming code, for example an
endless loop is not conforming in C++.
 Citation, please? How does it fail to conform?
It may well be I messed up something. I had a vague memory that g++ could legally optimize away the code only because it contained UB, but now I'm not so sure any more.

... The compiler is not obliged to
diagnose it, but it is allowed for the compiler to silently optimize the
non-conforming code away, assuming it is never called. At least that's
what g++ folks think.
 The C standard contains the following wording:
 "An iteration statement may be assumed by the implementation to
terminate if its controlling expression is not a constant expression200)
, and none of the following operations are performed in its body,
controlling expression or (in the case of a for statement)
itsfexpression-3201) :
— input/output operations
— accessing a volatile object
— synchronization or atomic operations."
 
It looks like they have clarified the rules in the last standard, my earlier draft (n4861) does not contain such verbiage.

In essence, those restrictions mean that the body of the loop does
nothing that need take up any time, so it can be optimized to a nop.
Infinitely many repetitions times 0 execution time has a product that is
mathematically meaningless, but the C standard permits optimizing to
terminate after a finite amount of time.
 Note that this does not apply to endless loops occurring by other means,
such as goto.
The 4861 draft gives an implementation of a while loop in terms of GOTO and says these are equivalent.

Date Sujet#  Auteur
23 May 24 * Compile time checking of standards conformance11olcott
23 May 24 `* Re: Compile time checking of standards conformance10Paavo Helde
23 May 24  +- Re: Compile time checking of standards conformance1olcott
23 May 24  +* Re: Compile time checking of standards conformance4olcott
23 May 24  i`* Re: Compile time checking of standards conformance3David Brown
23 May 24  i `* Re: Compile time checking of standards conformance2olcott
23 May 24  i  `- Re: Compile time checking of standards conformance1David Brown
23 May 24  +* Re: Compile time checking of standards conformance3James Kuyper
24 May 24  i`* Re: Compile time checking of standards conformance2Paavo Helde
24 May 24  i `- Re: Compile time checking of standards conformance1James Kuyper
24 May 24  `- Re: Compile time checking of standards conformance1Keith Thompson

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal