473,324 Members | 2,535 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

volatile?

Hi,

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

Rick

Nov 13 '05 #1
4 5776
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

Nov 13 '05 #2
"Rick" <rrquick@nospam-com> wrote in message
news:3f********@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.

Nov 13 '05 #3
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:

k2********************************@4ax.com.

Regards
--
Irrwahn
(ir*******@freenet.de)
Nov 13 '05 #4
In article <bm************@ID-203837.news.uni-berlin.de>,
vi*****@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: po********@sco.com
Nov 13 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: newsock | last post by:
Why need to qualify a member function "volatile"? Why need to qualify a object "volatile"? When need to "const_cast" away "volatile" of an object and a member function? I also saw some code...
8
by: Tim Rentsch | last post by:
Here's another question related to 'volatile'. Consider the following: int x; void foo(){ int y; y = (volatile int) x;
5
by: ben | last post by:
Hello All, I am trying to make sense of a bit of syntax, is there a guru out there that can clear this up for me. I have a buffer declared as static volatile u8 buffer; and I have a...
14
by: Ian Pilcher | last post by:
It's pretty common to see declarations such as: static volatile sig_atomic_t caught_signal = 0; C99 defines sig_atomic_t as a "... (possibly volatile-qualified) integer type of an object that...
14
by: google-newsgroups | last post by:
Hello, even (or because?) reading the standard (ISO/IEC 9899/1999) I do not understand some issues with volatile. The background is embedded programming where data is exchanged between main...
17
by: dingoatemydonut | last post by:
The C99 standard states: "In the abstract machine, all expressions are evaluated as specified by the semantics. An actual implementation need not evaluate part of an expression if it can deduce...
18
by: Mark | last post by:
Hi List, I want to write a function to copy some data out of a hardware buffer. The hardware can change the contents of this buffer without it being written to by my function. I want to use...
94
by: Samuel R. Neff | last post by:
When is it appropriate to use "volatile" keyword? The docs simply state: " The volatile modifier is usually used for a field that is accessed by multiple threads without using the lock...
3
by: Rakesh Kumar | last post by:
Hi - I am actually trying to get my feet in multi-threaded C++ programming. While I am aware that the C++ standard does not talk about threads (at least, for now - in C++03) - my question is more...
10
by: S James S Stapleton | last post by:
Is volatile necessary anymore? I have a two-thread piece of code I've been testing to figure out what volatile does (fairly simple code, uses pthreads). I have an update thread (variables passed as...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.