Yahoo Groups archive

AVR-Chat

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

Message

Re: Volatile modifier

2012-04-19 by bayramdavies

Gregory N wrote (in part):

> It seems to me that the lack of clarity is
> because people are attempting to define the
> volatile storage class based on when and how
> to use it, not what it is.

OK, well, the above is a kind-of self-fulfilling observation, because volatile isn't a storage class.  I don't want to get combative about this, but my personal opinion is that the lack of clarity is caused by people shooting from the hip.

> If you define volatile by what it is, then
> its usage follows ...

I think that this would not work for the less advanced users.  If you sat a group of people in a classroom and told them in great detail what a car is, not all of them would be able to go outside and drive one.

> The name volatile is itself misleading ...

Indeed, as are other C language keywords, such as const and static.

> ... job interview C question.  "What does
> the volatile storage class mean?"

An almost impossible question to answer.  If you ignore the mistake in calling volatile a storage class, the interviewer can assume that you don't know what a storage class is.  If you point this out and it turns out that the interviewer didn't intend this mistake, he or she will feel threatened by you and not hire you.
 
> volatile says don't optimize... don't convert
> the variable i to a register variable.

I'm going to try a shot from the hip here myself and say that I don't think that this is correct.  A variable declared in a function without the static storage class specifier has the storage class auto.  This defines the lifetime of the variable as the execution of the smallest enclosing block and the starting value as unspecified.  It says nothing about where the compiler has to put the variable.  The compiler can put it in a register (if one is available), on the data stack (if there is one) or in ordinary memory.  This is not an optimization issue and has nothing to do with the volatile type qualifier.

Graham Davies
ECROS Technology
www.ecrostech.com

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.