Re: while (1) vs. for ( ;; )



Charlie Gordon wrote:
"Keith Thompson" <kst-u@xxxxxxx> wrote in message
news:lnk6i4rojv.fsf@xxxxxxxxxxxxxxxxxx

"Charlie Gordon" <news@xxxxxxxxxxx> writes:

"akarl" <fusionfive@xxxxxxxxx> wrote in message
news:glPQe.32705$d5.187496@xxxxxxxxxxxxxxxxxx

[...]

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 ?...
}

That's solved by following a simple rule: never compare a value to a literal true or false. Comparing to true or false is both error-prone and useless. If an expression is a condition, just use it as a condition.

The existence of type bool doesn't mean you can't use

   while (isdigit(*s)) {
       ...
   }


I just meant to stress the point, that the C language is full of traps and
pitfalls... giving it a java flavor doesn't fix them.

You don't see the point. The `bool' type in stdbool.h is primarily for (self) documentation purposes. That a lint tool such as Splint can detect incorrect usage is an extra bonus.


August
.