Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > volatile?

Reply
Thread Tools

volatile?

 
 
Rick
Guest
Posts: n/a
 
      10-14-2003
Hi,

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

Rick

 
Reply With Quote
 
 
 
 
Allin Cottrell
Guest
Posts: n/a
 
      10-14-2003
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

 
Reply With Quote
 
 
 
 
Vijay Kumar R Zanvar
Guest
Posts: n/a
 
      10-14-2003
"Rick" <rrquick@nospam-com> wrote in message
news:3f8b6961$(E-Mail Removed)...
> 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.

 
Reply With Quote
 
Irrwahn Grausewitz
Guest
Posts: n/a
 
      10-14-2003
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:

http://www.velocityreviews.com/forums/(E-Mail Removed).

Regards
--
Irrwahn
((E-Mail Removed))
 
Reply With Quote
 
Randy Howard
Guest
Posts: n/a
 
      10-21-2003
In article <bmgblj$lvb3o$(E-Mail Removed)-berlin.de>,
(E-Mail Removed) 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: (E-Mail Removed)
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off




Advertisments