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

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

Re: [avr-gcc-list] Wrong excution order in 4.1.1, but not 3.4.5, regress


From: David Brown
Subject: Re: [avr-gcc-list] Wrong excution order in 4.1.1, but not 3.4.5, regression?
Date: Tue, 20 Feb 2007 17:25:09 +0100
User-agent: Thunderbird 1.5.0.9 (Windows/20061207)

Graham Davies wrote:
David Brown wrote (in part):

... I don't know if the C standard is clear on expressions such as "a = b = c", when some or all of these are volatile ...

It is clear. The assignment operator has right-to-left associativity so b = c is evaluated first. The result of an assignment is the value assigned. So, the value assigned to b is then assigned to a. I can't see how volatile could affect this, but it certainly can't make things less well-defined.


There are at least two of ways to interpret "a = b = c" while maintaining right-to-left associativity, when the variables are all volatile:

int x = c;              // volatile read of c
b = x;                  // volatile store to b
a = x;                  // volatile store to a

or

int x = c;              // volatile read of c
b = x;                  // volatile store to b
int y = b;              // volatile read of b
a = y;                  // volatile store to a


I don't know which of these is specified by the standard - I believe, but am not sure, that it is unclear.

At the risk of sounding patronising, I'd say that almost any code with
"a = b = c" expressions is incorrect code because it is far from clear
what you mean, and if volatiles are involved then it is undoubtedly wrong.

You don't sound patronizing, just wrong.


Code which is unclear to the writer and to readers is bad code. Certainly different programmers have different ideas of what is clear or not, but I think that when you get to the stage of experienced programmers looking up the semantics in the standards, the code is bad.

When the code is re-written to actually say what you mean, do you still get a difference?

This is a useful question/suggestion, however, and may shed some light on the problem.

Graham.




_______________________________________________
AVR-GCC-list mailing list
address@hidden
http://lists.nongnu.org/mailman/listinfo/avr-gcc-list





reply via email to

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