avr-gcc-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: [avr-gcc-list] Question about gcc preprocessing and port/pin assignm


From: Dave Hylands
Subject: RE: [avr-gcc-list] Question about gcc preprocessing and port/pin assignments
Date: Wed, 8 Dec 2004 15:20:58 -0800

Hi Graham,

> So, your feeling is that declaring SOME_REG volatile does not 
> require the compiler to generate a single assignment to it.  
> Hmm.  I though that assignments worked by evaluating the 
> expression on the right and then placing the result at the 
> lvalue on the left.  Deviations from this would be 
> optimizations that are only permissible if writes to SOME_REG 
> have no side-effects, which is not the case if I declare it 
> volatile. If this is not so, I will have to adjust my 
> understanding of the language.

The fact that assignment causes something to be stored in memory at all,
is technically a "side effect". Assignment is really just a special case
of an expression.

So statements like:
        
        a = (b = 3) + 4;

are legal. The only thing that the language promises is that all side
effects from the expression are completed before the next statement is
executed.

So, what this says to me, is that it's perfectly reasonable for the
compiler to take an expression like:

        x = 1 + 2 + 3;

and compile it as:

        tmp = 1;
        tmp += 2;
        tmp += 3;
        x = tmp;

or as:

        x = 1;
        x += 2;
        x += 3;

It's stuff like this that can sometimes make the embedded
programmer/device driver writer go crazy....

--
Dave Hylands
Vancouver, BC, Canada
http://www.DaveHylands.com/ 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]