[Info-vax] decrementing & for loops in C

Bob Eager rde42 at spamcop.net
Sat Jan 10 12:06:49 EST 2009


On Sat, 10 Jan 2009 13:28:19 UTC, billg999 at cs.uofs.edu (Bill Gunshannon)
wrote:

> > 
> >> {
> >>    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?

It is told...by the programmer. See my other post on the 'volatile' 
keyword. The compiler is doing nothing wrong - the language definition 
(in the case of C and others) allows it to make certain assumptions 
unless advised otherwise by the programmer.

> > 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.

I'd have written 'could access', which then makes perfect sense.

> 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.

Which is what the compiler does. Humans have to use the language spec. 
to express their wishes. If you're not keen on that, use a different 
language which guarantees never to optimise.

-- 
Bob Eager




More information about the Info-vax mailing list