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

Denys Vlasenko vda.linux at googlemail.com
Tue Nov 2 06:37:46 UTC 2010


On Monday 01 November 2010 04:49, Matthew Stoltenberg wrote:
> >> > 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.
>
> So it never mattered or doesn't matter now?  :)

I guess even the very early compilers were optimizing while (1) {...}
into infinite loop - they did not emit code to check that 1 is != 0.

-- 
vda


More information about the busybox mailing list