[asterisk-dev] code-cleanup concerns
Craig Southeren
craigs at postincrement.com
Fri Apr 14 19:43:19 MST 2006
On Fri, 14 Apr 2006 22:28:24 -0400
Mark Sirota <msirota at isc.upenn.edu> wrote:
> --On Friday, April 14, 2006 4:28 PM -0700 Brian Degenhardt
> <bmd at bmdhacks.com> wrote:
> > Unless somebody can explain why for(;;) is inferior to do{}while(1), or
> > why removing curly braces on one-line if statements is worth the
> > trouble of patch maintainers everywhere, I think this just does more
> > harm than good.
>
> Just FYI, from a 25-year C programming veteran: for (;;) is a more
> efficient loop than while (1) for some compilers, because there is no
> comparison to zero required. In modern reality most optimizers will make
> them identical, but it is conceivable that there might still be a system
> around that treats these literally. In any case, it's certainly clear to
> me that either of them is far more readable than do {} while (1)!
Some compilers print a warning for "while (1)" as this is a constant
expression. This warning is intended to catch typos like "while (v = 1)"
instead of "while (v == 1)".
The construct "for (;;)" does not generate a warning on any compiler I
am aware of.
Craig
-----------------------------------------------------------------------
Craig Southeren Post Increment VoIP Consulting and Software
craigs at postincrement.com.au www.postincrement.com.au
Phone: +61 243654666 ICQ: #86852844
Fax: +61 243673140 MSN: craig_southeren at hotmail.com
Mobile: +61 417231046
"It takes a man to suffer ignorance and smile.
Be yourself, no matter what they say." Sting
More information about the asterisk-dev
mailing list