Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C Programming (http://www.velocityreviews.com/forums/f42-c-programming.html)
-   -   volatile? (http://www.velocityreviews.com/forums/t315766-volatile.html)

Rick 10-14-2003 03:21 AM

volatile?
 
Hi,

What exactly is the volatile keyword for in C? and when should we use
it/ avoid it? Thanks

Rick


Allin Cottrell 10-14-2003 03:42 AM

Re: volatile?
 
Rick wrote:

> What exactly is the volatile keyword for in C? and when should we use
> it/ avoid it?


The 'volatile' keyword tells the C compiler that a particular
variable can change its value without warning, and that the
compiler should make no assumptions regarding this variable, of the
sort that compilers might be inclined to make when planning
optimizations.

As I understand it, this keyword is most likely to be used in
writing device drivers, and in general should be avoided unless
you know exactly what you are doing.

--
Allin Cottrell
Department of Economics
Wake Forest University, NC


Vijay Kumar R Zanvar 10-14-2003 08:16 AM

Re: volatile?
 
"Rick" <rrquick@nospam-com> wrote in message
news:3f8b6961$1@clarion.carno.net.au...
> Hi,
>
> What exactly is the volatile keyword for in C? and when should we use
> it/ avoid it? Thanks
>


You can find good information about volatile here:

http://www.programmersheaven.com/art...k/article1.htm

--
A four-month crash course is being imparted to these militants
and the first batch would soon be out to be used for sabotage
operation in high altitude areas in J&K borders, they said.


Irrwahn Grausewitz 10-14-2003 10:01 AM

Re: volatile?
 
Rick <rrquick@nospam-com> wrote:

>What exactly is the volatile keyword for in C? and when should we use
>it/ avoid it? Thanks


This question has been asked and answered here in c.l.c two days ago.
Please refer to the thread starting with message:

k23jov0166kf0blsde8581cff7una9uh0l@4ax.com.

Regards
--
Irrwahn
(irrwahn33@freenet.de)

Randy Howard 10-21-2003 08:08 PM

Re: volatile?
 
In article <bmgblj$lvb3o$1@ID-203837.news.uni-berlin.de>,
vijoeyz@hotmail.com says...
> You can find good information about volatile here:
>
> http://www.programmersheaven.com/art...k/article1.htm


Sadly OT for c.l.c:
Except for the part about using it for shared data between threads.
It is an unfortunately com mom misconception that volatile can be
used in threaded code as a synch method. It is necessary to
in such programs to avoid the compiler optimizing out a loop on
a variable that might be modified in another thread. There are
typically better (I.e. more efficient) methods of doing that
in most thread libraries. Nevertheless, using volatile for such
conditions does not obviate the need for (insert favorite locking
mechanism, such as mutex, critical section, ....).

The article does not make that clear, so reader beware that
things as complicated as thread programming typically aren't
explained sufficiently in a single short article. This one
included. :-)

--
Randy Howard _o
2reply remove FOOBAR \<,
______________________()/ ()______________________________________________
SCO Spam-magnet: postmaster@sco.com


All times are GMT. The time now is 04:24 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.