Re: C23 thoughts and opinions

Liste des GroupesRevenir à cl c 
Sujet : Re: C23 thoughts and opinions
De : Keith.S.Thompson+u (at) *nospam* gmail.com (Keith Thompson)
Groupes : comp.lang.c
Date : 04. Jun 2024, 00:23:57
Autres entêtes
Organisation : None to speak of
Message-ID : <87le3l1ugi.fsf@nosuchdomain.example.com>
References : 1 2 3 4 5 6 7 8
User-Agent : Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
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 */

Date Sujet#  Auteur
31 May 24 * Re: C23 thoughts and opinions20Lynn McGuire
1 Jun 24 +- Re: C23 thoughts and opinions1David Brown
2 Jun 24 `* Re: C23 thoughts and opinions18Lawrence D'Oliveiro
2 Jun 24  +- Re: C23 thoughts and opinions1Keith Thompson
2 Jun 24  `* Re: C23 thoughts and opinions16Kenny McCormack
2 Jun 24   `* Re: C23 thoughts and opinions15Lew Pitcher
2 Jun 24    +* Re: C23 thoughts and opinions13Kaz Kylheku
3 Jun 24    i+- Re: C23 thoughts and opinions1Michael S
3 Jun 24    i+* Re: C23 thoughts and opinions5Tim Rentsch
3 Jun 24    ii`* Re: C23 thoughts and opinions4Chris M. Thomasson
3 Jun 24    ii `* Re: C23 thoughts and opinions3Kenny McCormack
4 Jun 24    ii  `* Re: C23 thoughts and opinions2David Brown
4 Jun 24    ii   `- Re: C23 thoughts and opinions1Chris M. Thomasson
3 Jun 24    i`* Re: C23 thoughts and opinions6bart
4 Jun 24    i +* Re: C23 thoughts and opinions2Keith Thompson
4 Jun 24    i i`- Re: C23 thoughts and opinions1David Brown
4 Jun 24    i +* Re: C23 thoughts and opinions2Lawrence D'Oliveiro
4 Jun 24    i i`- Re: C23 thoughts and opinions1David Brown
4 Jun 24    i `- Re: C23 thoughts and opinions1Kaz Kylheku
3 Jun 24    `- Re: C23 thoughts and opinions1Tim Rentsch

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal