[Info-vax] decrementing & for loops in C

Johnny Billquist bqt at update.uu.se
Mon Jan 12 17:38:59 EST 2009


Bill Gunshannon skrev:
> In article <176uZD2KcidF-pn2-o5JGhldCleMl at rikki.tavi.co.uk>,
> 	"Bob Eager" <rde42 at spamcop.net> writes:
>> 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.
> 
> And, how does the compiler know that the memory address of "power_level"
> is a device register as opposed to a memory location?  An address is an
> address.  There is no way that I can think of that the compiler could
> know anything about the hardware the programis going to eventually be
> executed on.  Unless it can read the comments.  :-)

There is actually a reserved word in C for telling exactly that. "volatile". :-)

	Johnny

-- 
Johnny Billquist                  || "I'm on a bus
                                   ||  on a psychedelic trip
email: bqt at softjar.se             ||  Reading murder books
pdp is alive!                     ||  tryin' to stay hip" - B. Idol



More information about the Info-vax mailing list