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/pinassignme


From: Dave Hansen
Subject: Re: [avr-gcc-list] Question about gcc preprocessing and port/pinassignments
Date: Thu, 09 Dec 2004 12:46:58 -0500

From: "Graham Davies" <address@hidden>
[...]
I'm a bit nervous that I've dragged this thread too far off topic and I'm on
the verge of changing the subject line but I've not figured out the list
practices in that regard.  Anyway, people do seem to be interested so this
is where I think we are.

x = exp; // when exp is some simple expression, possibly including the value
of x
Question - is the compiler permitted to implement this with multiple stores
to x if x is declared volatile?

I don't believe so.


I note that we must distinguish:
A - What we would like to happen.
B - What the language definition says must happen.
C - What actually happens in any given implementation.

It's difficult for the C standard to constrain non-comforming implementation...

[...]
>From section 5.1.2.3, page 25 of the PDF: "In the abstract machine, all
expressions are evaluated as specified by the semantics."

>From section 6.7.3, page 120 of the PDF: "... any expression referring to
[an object that has volatile-qualified type] shall be evaluated strictly
according to the rules of the abstract machine, as described in 5.1.2.3."

Taken together and reinforced by other text, these statements suggest to me
that the compiler is not permitted to introduce optimizations or other
changes that would result in multiple stores to a volatile-qualified lvalue.

Depends on the expression.  But counter-examples invoke undefined behavior.

From 6.5p2:

"Between the previous and next sequence point an object shall have its stored value modified at most once by the evaluation of an expression. Furthermore, the prior value
   shall be read only to determine the value to be stored."

So, given an expression similar to your earlier example,

  x = (x & 0xF0) | 0x20;

If we examine the semantics of the operators, only '=' says it stores a value into its lhs. OTOH, given the classic

  x = x++;

Both '=' and '++' cause a value to be stored in x, but of course 6.5p2 says that's undefined.

That's the way I read it, anyway.  Regards,
  -=Dave




reply via email to

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