[Info-vax] decrementing & for loops in C

Bill Gunshannon billg999 at cs.uofs.edu
Sat Jan 10 08:28:19 EST 2009


In article <0053c479$0$4682$c3e8da3 at news.astraweb.com>,
	JF Mezei <jfmezei.spamnot at vaxination.ca> writes:
> Bill Gunshannon wrote:
> 
>> it is what I wrote.  But, the system should not be changing the order of
>> operations for any code I wrote because it has absolutely no way of
>> determining that there was not a particular reason for doing it in that
>> order. 
> 
>> {
>>    int thrust_reversers, power_level;
>> 
>> { thrust_reversers = 10; power_level = 20; }
>> }
> 
> If both variables are declared locally with no code executing between
> the 2 assignments, then it doesn't matter in what order they execute.

And if they are actually addresses that map to control registers.....

And how is the compiler supposed to ne able to tell the difference?

See my point?

> 
> If you had:
> 
> thrust_reversers = 10;
> synchronize();
> power_level = 20;
> synchronize();
> 
> AND both variables were declared globally (aka: accessible by
> synchronize), then the compiler couldn't change the order because it
> would know that synchronize would access/modify those variables.

How would it "know" that?  It might assume that, but it has absolutely
no way to "know" that.  The programmer probably does, but not the
compiler.

> 
> But if the variables arecreated locally, then no code could access it
> and it wouldn't matter. In fact, if the variables are created locally
> and not used elsewhere in that subroutine, the whole variable would be
> optimized away since it is not used after the assignment and destroyed
> when the subroutine returns and its stack deallocated.
> 
> The fine compiler writers have spent years looking at various ways to
> optimize code and they know whatcan and cannot be optimized.

But they can not possibly know what the real world effect of any
statement within a program being passed to their compiler is.  You
can trust the machine if you wish, I will leave my trust in the hands
of humans.

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