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

P E Smee exspes at gdr.bath.ac.uk
Fri May 25 19:21:50 AEST 1990


In article <12971 at smoke.BRL.MIL> gwyn at smoke.BRL.MIL (Doug Gwyn) writes:
>If a compiler is going
>to generate a useless comparison, it is in fact more likely
>to do so for while(1) than for for(;;).

One benefit of 'for(;;)' over 'while (1)' which I haven't seen
mentioned is that most (in my experience) versions of 'lint' will
cheerfully accept 'for(;;)' without comment, while giving a 'constant
in conditional' warning for 'while(1)'.

You could plausibly argue that lint is broken and should recognize this
use of while as a special case.  You could also plausibly argue that C
should have an explicit 'do forever' construct.  However, neither of
these seem to be true, and I have no control over them; I can control
my code and like it to be lint-free (or as near as possible -- 'There
are some things you just cant get lint to shut up about' from lint(1)).

(Yeah, I know how to hide things from lint.  I don't like to do that,
though, for fear that I'll make a REAL error which it would have
caught, somewhere where it can't see it because I've hidden it.)

-- 
Paul Smee, Computing Service, University of Bristol, Bristol BS8 1UD, UK
 P.Smee at bristol.ac.uk - ..!uunet!ukc!bsmail!p.smee - Tel +44 272 303132



More information about the Comp.std.c mailing list