Re: [cc65] How to force a read from a memory mapped register w/o volatile

From: Dave Dribin <ddribin1gmail.com>
Date: 2010-12-06 15:53:32
On Mon, Dec 6, 2010 at 6:09 AM, Oliver Schmidt <ol.sc@web.de> wrote:
> I don't agree at all. The 'volatile' keyword tells the compiler not to
> cache values read but to rather presume they might have beeen changed
> at any time (by other threads, ISRs, MM I/O, ...). The 'volatile'
> keyword does *not* tell the compiler that any read/write may have side
> effects necessary and therefore needs to be performed always.

I believe the C99 standard [1] does call out side effects. (I don't
have a copy of the C89 standard, but it's should be the same/similar
for 'volatile').  Section 6.7.3, paragraph 6:

"An object that has volatile-qualified type may be modified in ways
unknown to the implementation or have other unknown side effects."

Note 114 further clarifies:

"A volatile declaration may be used to describe an object
corresponding to a memory-mapped input/output port or an object
accessed by an asynchronously interrupting function. Actions on
objects so declared shall not be ‘‘optimized out’’ by an
implementation or reordered except as permitted by the rules for
evaluating expressions."

-Dave

[1]: http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1124.pdf
----------------------------------------------------------------------
To unsubscribe from the list send mail to majordomo@musoftware.de with
the string "unsubscribe cc65" in the body(!) of the mail.
Received on Mon Dec 6 15:53:40 2010

This archive was generated by hypermail 2.1.8 : 2010-12-06 15:53:43 CET