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

Trevor John Thompson tj at mks.com
Fri Jun 1 05:54:45 AEST 1990


In article <5927 at buengc.BU.EDU> bph at buengc.bu.edu (Blair P. Houghton) writes:
>In article <4298 at castle.ed.ac.uk> aipdc at castle.ed.ac.uk (Paul D. Crowley) writes:
>>* You raised the issue because the standard states that for(;;) means
>>for (;1;) which you said meant that it could be no more efficient than
>>while(1).  Since everybody already knew they were identical in meaning,
>>seems to me all you can be talking about is the efficiency of the code
>>generated.  In other words, the standard specified that the _code_
>>_generated_ must have an extra comparison.
>
>Now _you're_ missing the condition that the implementor's
>implied that it's not optimizing.  If it has, then your
>last statement should be true.  If it hasn't, that statement
>may or may not be true.
>
>>* If you're not worried about the code generated so long as it does what
>>the standard says it should, why the hell were you complaining about
>>"optimization without your permission"?
>
>Because I don't like compilers that get ahead of my debugging.
>When the time comes to make the object code tiny and quick, it
>will have at least been confirmed logically (to some level
>of satisfaction).
>
>>* I seem to remember your saying that a compiler which didn't produce
>>the same code for these two cases would be breaking the law, if it
>>claimed to adhere to the ANSI standard.
>
>It also had to claim to eschew all forms of optimization.

It would appear that Mr. Houghton has some unusual notions of what
constitutes optimization; which i would guess are not based on
any practical experience with compiler writing. I suggest that
most readers of this group understand optimization to refer to
the kind of program transformation that is based on heuristics,
or falsifiable assumptions, or time and space expensive analysis,
and that the user can request either be applied or eschewed.

Generating an unconditional loop, rather than a test of a constant
followed by a conditional branch, for while(1), is generally
considered good code generation strategy, not an "optimization".
It requires no expensive program analysis to discover that the
unconditional loop is a superior code burst in time and space.
The existence of (old) compilers that do not implement this
strategy does not in any way diminish its validity.

One wonders just how bad code generation must be to satisfy
Mr. Houghton's notions of "non-optimized".
If his debugging techniques rely on the compiler *not* making
such transformations, then he needs a better debugger, or
a better compiler, or better programs.
-- 
     ||  // // ,'/~~\'   Trevor John Thompson  //C++ a strongly hyped language
    /||/// //|' `\\\     Mortice Kern Systems Inc.
   / | //_// ||\___/     35 King St. N., Waterloo, Ont., Can. N2J 2W9
O_/                      tj at mks.com  Vox: 519-884-2251  Fax: 519-884-8861



More information about the Comp.std.c mailing list