for(;;) vs. while(1) is a draw

Karl Heuer karl at haddock.ima.isc.com
Sat Jun 2 02:34:30 AEST 1990


In article <13025 at smoke.BRL.MIL> gwyn at smoke.BRL.MIL (Doug Gwyn) writes:
>... empty subject.  There is no implementor dumb enough to attempt to make
>such a claim ...

This is why I said Blair's statements were vacuously true.


Here's the recap, for those who tuned in late:

* A lot of people don't really care whether you use for(;;) or while(1), and
  wish that such discussion, if it is to take place at all, should be in
  alt.religion.computers.

* Blair happens to prefer while(1) for some reason.  Most of us don't care
  why.

* Evidently someone once told Blair of a compiler that produced slightly
  better code for the `for' statement.  I believe I've seen such a compiler.

* The better-code argument is pretty weak, since any compiler that overlooks
  such an obvious optimization is doing such a poor job that you'd better not
  be using it for anything where you care about compiler efficiency.  At best,
  you can use this argument as a tie-breaker.  (E.g. this is why I originally
  settled on using `++i' rather than `i++'.)

* Blair noted that the ANS, in describing the `for' statement, uses wording
  that (correctly) describes `for(;;)' as equivalent to `while(1)'.  He
  mistakenly thought that this wording was more than just a convenient way to
  describe the semantics, and used this to rebut the better-code argument.

* It turns out the K&R 1 actually does contain a similar clause, not that it
  matters.

* No sane vendor, in the process of upgrading a Classic C compiler to ANSI C,
  is going to change the way code is generated for `for' or `while' on the
  basis of this wording.  Thus, it remains true that `for(;;)' is slightly
  less likely to generate a useless compare.

* A lot of people don't really care whether you use for(;;) or while(1), and
  wish that such discussion, if it is to take place at all, should be in
  alt.religion.computers.

Karl W. Z. Heuer (karl at ima.ima.isc.com or harvard!ima!karl), The Walking Lint
(Isn't this subject in your KILL file yet?)



More information about the Comp.std.c mailing list