Posts Tagged ‘-O2’

Volatile: C Keyword Myths Dispelled

Tuesday, February 24th, 2009

Subscribe To Our Feed | Follow Us On Twitter | Get Updates on Email

Last time we explained the real meaning of const keyword, this time it’s going to be Volatile, the other sibling of this most misunderstood duo in C history. Let’s separate out the myths and the facts first and then we will discuss the how’s and why’s of it.

FACTS:

  • A volatile qualifier is important to be used for auto-storage variables within setjmp and longjmp.
  • A volatile qualifier must be used when reading the contents of a memory location whose value can change unknown to the current program.
  • A volatile qualifier must be used for shared data modified in signal handlers or interrupt service routines.

MYTHS:

  • All shared data in multi-threaded programs must be declared volatile.

Now, we’ll see how we made the above classfication.

(more…)

© Safer Code | Volatile: C Keyword Myths Dispelled

Liked this post? Get FREE Updates
Subscribe to RSS feed

Or
Enter Your E-mail ID below