[Info-vax] decrementing & for loops in C

Bill Gunshannon billg999 at cs.uofs.edu
Fri Jan 9 08:53:49 EST 2009


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.

bill

-- 
Bill Gunshannon          |  de-moc-ra-cy (di mok' ra see) n.  Three wolves
billg999 at cs.scranton.edu |  and a sheep voting on what's for dinner.
University of Scranton   |
Scranton, Pennsylvania   |         #include <std.disclaimer.h>   



More information about the Info-vax mailing list