Yahoo Groups archive

AVR-Chat

Index last updated: 2026-04-28 22:41 UTC

Message

Re: [AVR-Chat] Re: Volatile modifier

2012-04-21 by Robert Adsett

On 4/20/2012 9:49 PM, Brian Dean wrote:
> The essence of it is that it instructs the compiler that this
> "storage area", is, as the name implies, volatile.Meaning, the
 > content may change outside of the compiler's compile-time knowledge,


Actually it doesn't.  If it did

const volatile int f;

would be invalid, rather than being useful.

Note also that const does not mean constant.

> or, in the case of some hardware ports/registers, accesses to said
> storage have side effects hardware related side-effects (clearing of
> certain bits after a read, and things like that).

That extends the dictionary definition beyond recognition. The 
comparison to the standard english meaning of volatile breaks down here.

Explaining volatile in the context of interrupts and status registers is 
a good introduction but leaving the understanding at that point would be 
a disservice, it leads to the misunderstandings that have been rife in 
this discussion.  Layering additional meaning on top in an "it also 
means a, b, c" fashion makes the definition needlessly complex.

As far as volatile being misnamed it's not the first time programming 
languages have taken a general term and given it a definition that isn't 
strongly related to it's usual definition and it won't be the last.  I 
haven't heard a better suggestion and it's too late in any case.

Actually the definitions of const and volatile leave a gaping hole in 
the qualifications needed for I/O register access.  They provide no way 
to define a write only variable. There no way to inform the compiler 
that a particular variable may not be read.

Robert

-- 

  From the Divided by a Common Language File (Edited to protect the guilty)
ME - "I'd like to get Price and delivery for connector Part # XXXXX"
Dist./Rep - "$X.XX Lead time 37 days"
ME - "Anything we can do about lead time?  37 days seems a bit high."
Dist./Rep - "that is the lead time given because our stock is live....
we currently have stock."

Attachments

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.