[Info-vax] decrementing & for loops in C

Bob Eager rde42 at spamcop.net
Fri Jan 9 13:12:21 EST 2009


On Fri, 9 Jan 2009 17:35:56 UTC, billg999 at cs.uofs.edu (Bill Gunshannon) 
wrote:

> Well, let's be clear on this.  By "exactly as written" I mean just what it
> says.  Not "as the writer intended", but "exactly as written".  That allows
> for optimizing out code that would never be executed because I wrote the 
> code wrong, like the original example.  It may not be what I wanted, but
> 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.

Lots of compilers re-order operations. So do lots of CPUs; the Pentium 
does it, and I suspect some VAXes do, as well (although this kind of 
thing is relatively modern).

> "Let's see.  The programmer wants me to check for weight on the wheel
>  struts before raising the landing gear.  but I think it would be much
>  more efficient to raise the gear first."   :-)
>  
> What, you say that's just silly.  How about this?
>  
> {
>    int thrust_reversers, power_level;
>  
> { thrust_reversers = 10; power_level = 20; }
> }
>  
> Does the order of these two (apparently) equal operations make a difference?

If they are assignments to simple variables, no. If they were function 
calls, then the compiler wouldn't know, and wouldn't re-order them. 
Likewise for access to device registers.

Compilers are generally allowed to re-order stuff in blocks of code 
(i.e. those without branches) as long as execution of none of that block
generates side effects (which is basically what I just said).

-- 
Bob Eager




More information about the Info-vax mailing list