Re: while (1) vs. for ( ;; )
- From: "Charlie Gordon" <news@xxxxxxxxxxx>
- Date: Tue, 30 Aug 2005 05:39:50 +0200
"akarl" <fusionfive@xxxxxxxxx> wrote in message
news:glPQe.32705$d5.187496@xxxxxxxxxxxxxxxxxx
> Charlie Gordon wrote:
> > "Chris McDonald" <chris@xxxxxxxxxxxxxxx> wrote in message
> > news:detv2b$ael$1@xxxxxxxxxxxxxxxxxx
> >
> >>Ben Pfaff <blp@xxxxxxxxxxxxxxx> writes:
> >>
> >>I would suggest that both while(1) and for(;;) are potentially unclear
> >>to a person (undergrad. student) seeing C for the first time
> >>(while assuming they haven't seen Java or C++, either).
> >>
> >>OK, I suggest that while(true) is *clearer*.
> >
> In variable and function declarations the virtues of stdbool.h is clear.
> Compare
>
> int isThisAPredicate;
>
> and
>
> bool thisMustBeAPredicate;
You are right, but things are a bit more complicated than this: pretending to
clean up the C language is doomed.
Just look at :
#include <stdbool.h>
#include <ctype.h>
....
while (isdigit(*s) == true) {
... sometime works, sometimes not ?...
}
coming from java, you can be used to writing while(true) { ... } but then this
works too :
#if true
.... this code will compile :
.... It is a good thing the ISO folks made it work... as a consequence, true and
false are plain untyped integral literals.
#endif
I think it is better for people who see C for the first time to not get the
false idea that le language is easy.
The common idiom to loop forever is for (;;) { ... } . It catches the eye
instantly, why make it less obvious by burying semantics in less distinctive
wording ?
I especially don't like while(1) { ... } because it can be confused with while
(l) { ... } and vice versa.
Naming a variable l is of course a bad idea, but a quite common occurrence in
fact.
--
Chqrlie.
.
- Follow-Ups:
- Re: while (1) vs. for ( ;; )
- From: Keith Thompson
- Re: while (1) vs. for ( ;; )
- References:
- while (1) vs. for ( ;; )
- From: Michael B Allen
- Re: while (1) vs. for ( ;; )
- From: Chris McDonald
- Re: while (1) vs. for ( ;; )
- From: Ben Pfaff
- Re: while (1) vs. for ( ;; )
- From: Chris McDonald
- Re: while (1) vs. for ( ;; )
- From: Charlie Gordon
- Re: while (1) vs. for ( ;; )
- From: akarl
- while (1) vs. for ( ;; )
- Prev by Date: Re: compare a large number of variables
- Next by Date: Re: Problem in Strdup()
- Previous by thread: Re: while (1) vs. for ( ;; )
- Next by thread: Re: while (1) vs. for ( ;; )
- Index(es):
Relevant Pages
|