Yahoo Groups archive

AVR-Chat

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

Message

Re: Volatile modifier

2012-04-21 by bayramdavies

R E Purcella wrote:

> I think you are nit picking words.

Well, yes, of course I'm nit picking words.  I have taken it upon myself to try to get the use of the volatile qualifier straightened out.  The only tool I have to do that is words.  How can I expect to communicate precisely if I don't use words precisely?

For example, take the "unassailable" statement that you should use the volatile qualifier when declaring a variable that represents a special function register.  The only reason that you understand and accept that is that you *misunderstand* the word "variable" or patch up the vague word "represents".  You actually can't declare a variable to directly stand in for an SFR because if you declare a variable the compiler and linker get to choose where to put it and you can't (without using stupid linker tricks) get past that to put the variable where the SFR is.

What you can do, is declare and define a pointer variable, the value of which is initialized to the address of the SRF, and then de-reference that to access the SFR.  Then you do not declare that pointer variable as volatile qualified type (you should rather declare it const).  You declare it as a pointer to a volatile qualified type.  This is important!  If you think that the pointer "represents" the SFR and declare it volatile, instead of the type it points to, you will not get the intended behavior and it will be very hard for you to figure out why.

Alternatively, as in the AVR gcc header files, you can use a pre-processor macro to define a combined type cast and de-reference of a manifest constant and then use that macro as if it were a variable.  But, it isn't a variable.  There is no variable.  We're directly accessing an address in a certain way (according to the type cast) without a variable.

My position, which you can criticize if you like, is that if I'm going to try to explain something I should neither a) assume that the reader already knows enough about that thing to read past any sloppy use of words nor b) expect that the reader will misunderstand a word in the same way that I do.  If I'm going to put an explanation forward, it is my duty to use all reasonable efforts to make sure that explanation is complete, correct and understandable by my target audience.

Having written the above, it now occurs to me that I don't belong on the Internet.

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.