[Info-vax] decrementing & for loops in C
JF Mezei
jfmezei.spamnot at vaxination.ca
Fri Jan 9 15:57:18 EST 2009
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.
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.
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.
More information about the Info-vax
mailing list