[Info-vax] decrementing & for loops in C

Richard B. Gilbert rgilbert88 at comcast.net
Fri Jan 9 11:19:07 EST 2009


Bill Gunshannon wrote:
> In article <49667A6E.3050507 at nowhere.com>,
> 	nobody <nobody at nowhere.com> writes:
>> vaxinf at chemie.uni-konstanz.de wrote:
>>> Hi,
>>>
>>> I tried to run one of the example found on Jim Duff's homepage and
>>> found a behavior of for loops written in C:
>>
>> Others have commented about the program not working, so I won't.
>>
>> Another thing you may experience with some compilers is that the result 
>> will be that both loops go in the same direction no matter what you 
>> write. The reason beeing that an optimizing compiler may realize that 
>> you are not doing anyting inside the loop that forces you to do it in a 
>> special order. Therefore it may choose to turn one of them around in 
>> order to do the execution faster.
> 
> I would consider that compiler to be broken.  Changing the logic of the
> program is not optimization.
> 
>> I must admit I have never seen this in a C program since I'm really not 
>> a C programmer. But I have seen it in Ada and in Pascal.
> 
> I have never seen it, but then I have never looked for it.  It wouldn't
> surprise me with Ada, however.  See my comment above. :-)
> 
>> Turning off optimization should normally cause the program to execute 
>> your program exactly as written.
> 
> A program should always execute exactly as written.  No machine is smart
> enough to second guess the intent of a human.
> 

A program does exactly that.  This is both the greatest strength and the 
greatest weakness of a program.  It does EXACTLY what's written and 
that's not necessarily exactly what the programmer intended!!

And this is the first principle of debugging!






More information about the Info-vax mailing list