Deutsch   English   Français   Italiano  
<87le3l1ugi.fsf@nosuchdomain.example.com>

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

Path: ...!news.nobody.at!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Keith Thompson <Keith.S.Thompson+u@gmail.com>
Newsgroups: comp.lang.c
Subject: Re: C23 thoughts and opinions
Date: Mon, 03 Jun 2024 16:23:57 -0700
Organization: None to speak of
Lines: 56
Message-ID: <87le3l1ugi.fsf@nosuchdomain.example.com>
References: <v2l828$18v7f$1@dont-email.me>
	<v2o57g$1t5p4$1@raubtier-asyl.eternal-september.org>
	<v3dkgh$2e0me$1@dont-email.me> <v3gou9$36n61$3@dont-email.me>
	<v3hrq7$1o743$1@news.xmission.com> <v3i7u3$3bp0v$1@dont-email.me>
	<20240602124448.704@kylheku.com> <v3lgti$325i$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Date: Tue, 04 Jun 2024 01:23:57 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="90afdb6d92dd2740ec1db4216de117c0";
	logging-data="103375"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX18oi6d+l2Vn8hirsYqng2Ot"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock: sha1:IaoUjvLty/+K8LlJMMx6vHLDy/E=
	sha1:aLuAdF5P5c47ebUKZ4ELepvQdMs=
Bytes: 2970

bart <bc@freeuk.com> writes:
[...]
> At this point someone will suggest a macro this:
>
>   #define forever for(;;)

When I was first learning C, I defined a macro, something like:

    #define ever ;;

so that I could write

    for (ever) {
        /* ... */
    }

At the time, I thought it was very clever.

I still think it was very clever.  But I no longer think that's a
good thing.

> All that suggest sto me is that the language *needs* an explicit
> endless loop!

No, it doesn't.

There are multiple valid and idiomatic ways to write an infinite
loop in C:

    for (;;)
    while (1)
    while (true) // requires C99 or later and #include <stdbool.h>,
                 // or C23 or later without the #include,
                 // or your own "true" macro.

There is nothing wrong with any of them.  All C programmers should
immediately recognize each of them as an infinite loop.  The compiler
might have to do a few different things internally to process each
one -- and that makes no difference to me as a programmer.  If a
compiler generated different code for different forms, I probably
wouldn't notice.  If I bothered to check, I'd be mildly curious
about the reasons, and annoyed if one form was more efficient.

A language designed from the beginning with syntactic and semantic
elegance in mind might have only one explicit form of infinite loop
(though something like "while (true)" or "while (1+1==2)" would
still be allowed).  C is not that language.

I suspect some of the people in this thread saying that one form
is obviously better than the others are joking.

It doesn't matter.

-- 
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
void Void(void) { Void(); } /* The recursive call of the void */