Deutsch   English   Français   Italiano  
<v2o107$1s6ap$1@dont-email.me>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: James Kuyper <jameskuyper@alumni.caltech.edu>
Newsgroups: comp.lang.c,comp.lang.c++
Subject: Re: Compile time checking of standards conformance
Date: Thu, 23 May 2024 14:13:26 -0400
Organization: A noiseless patient Spider
Lines: 36
Message-ID: <v2o107$1s6ap$1@dont-email.me>
References: <v2m01g$1dcof$1@dont-email.me> <v2mndf$1kk52$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Thu, 23 May 2024 20:13:28 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="bab10d1b8655f980963d8d261836412b";
	logging-data="1972569"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX1/Nje8F2t9dSfRufWxUqYs9aVn0KFOphJ4="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:NuxUQ5HI31wq2ZbHokLKIBsw7tE=
Content-Language: en-US
In-Reply-To: <v2mndf$1kk52$1@dont-email.me>
Bytes: 2608

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?

> ... 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."

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 optimization you describe would therefore be permitted for C if
those conditions are met - but I can find no corresponding language in
the latest draft I have of the C++ standard (n4928.pdf, dated
2022-12-18). It's a big standard - I might have missed something.