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: Richard Urwin
Subject: Re: [avr-gcc-list] Question about gcc preprocessing and port/pin assignments
Date: Thu, 9 Dec 2004 00:04:59 +0000
User-agent: KMail/1.5.3

On Wednesday 08 Dec 2004 11:20 pm, Dave Hylands wrote:
> 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;

I would say that a volatile should only be written to as many times as 
the code says. After all if the data sheet says x is a command, where 
every value has a different effect, then your first version gives the 
correct effect, and your second gives two spurious different effects. 
If x is write-only then the second example would totally fail.

That bug cannot be protected against:
x=1
could conceivably be compiled as
x=0
inc x
(That may be space-efficient on some processors.)
If the programmer cannot protect against a problem then the compiler has 
to provide the tools to do it. It seems common-sense to me that that 
tool is 'volatile'.

-- 
Richard Urwin


reply via email to

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