Yahoo Groups archive

AVR-Chat

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

Message

Re: Volatile modifier

2012-04-17 by bayramdavies

R E Purcella wrote:

> As I understand it, Volatile variables are
> used when the variable is expected to be
> changed in Interrupt routines.

That is one situation.  See Don Kinzer's post of Apr 13 for others.

> Otherwise most global variables are by
> nature changeable at any time.

No, this is not true.  If a "global" variable (one with external linkage) is not declared volatile, then the compiler will assume that it cannot change during the execution of the code being compiled other than by an assignment it can see within that code.

> But, interrupt routines do not normally allow
> outside variables to be changed unless they are 
> volatile. Otherwise pointers must be used.

I can't make any sense of this.  You can do whatever you want in an interrupt service routine, there is no issue of being "not allowed" to do certain things.

> Further, volatile variables need to be declared
> in your global section.

No, you can write the declaration of a global variable anywhere you want to, according to your style and needs.
 
> i suggest this link efundies.com

I suggest that for complex issues such as this you avoid sites that describe themselves as "a collection of fun, free, electronics projects and advice" and instead stick to places visited by a good number of professionals who are likely to know what they are talking about.

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.