OT: for(;;) vs while(1)

Denys Vlasenko vda.linux at googlemail.com
Mon Nov 1 01:21:40 UTC 2010


On Monday 01 November 2010 01:42, Ken Irving wrote:
> On Sun, Oct 31, 2010 at 05:17:34PM -0500, Rob Landley wrote:
> > On Thursday 28 October 2010 16:10:35 Denys Vlasenko wrote:
> > 
> > >-	bunzip_data *bd;
> > > 	int i;
> > >+	unsigned len;
> > >
> > > 	outbuf = xmalloc(IOBUF_SIZE);
> > >-	i = start_bunzip(&bd, src_fd, NULL, 0);
> > >-	if (!i) {
> > >-		for (;;) {
> > >-			i = read_bunzip(bd, outbuf, IOBUF_SIZE);
> > >-			if (i <= 0) break;
> > >-			if (i != full_write(dst_fd, outbuf, i)) {
> > >-				i = RETVAL_SHORT_WRITE;
> > >-				break;
> > >+	len = 0;
> > >+	while (1) { /* "Process one BZ... stream" loop */
> > 
> > I still viscerally cringe when I see while (1) instead of for(;;).  I'm aware 
> > that modern optimizers take it out, but when there is a way to state exactly 
> > what you want the code to do and you choose to instead say something you 
> > _don't_ want the code to actually look like, I don't understand why.  Oh well.
> 
> I'm interested in this point, but can't find any arguments or discussion
> on the for(;;) vs while(1) issue.  It is just a style preference, i.e., 
> a religious issue?

Yes.

> I have seen for(;;) promoted over while(1), but why?

No reason.

-- 
vda


More information about the busybox mailing list