By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,443 Members | 1,409 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,443 IT Pros & Developers. It's quick & easy.

Volatile?

P: n/a
What does volatile keyword actually used for?

May 26 '07 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Shraddha skrev:
What does volatile keyword actually used for?
http://publications.gbdirect.co.uk/c..._volatile.html

nice explanation
May 26 '07 #2

P: n/a
Shraddha wrote:
>
What does volatile keyword actually used for?
See the C standard, which includes:

-- At sequence points, volatile objects are stable in the
sense that previous accesses are complete and
subsequent accesses have not yet occurred.

and

[#6] An object that has volatile-qualified type may be
modified in ways unknown to the implementation or have other
unknown side effects. Therefore any expression referring to
such an object shall be evaluated strictly according to the
rules of the abstract machine, as described in 5.1.2.3.
Furthermore, at every sequence point the value last stored
in the object shall agree with that prescribed by the
abstract machine, except as modified by the unknown factors
mentioned previously.105) What constitutes an access to an
object that has volatile-qualified type is implementation-
defined.

--
<http://www.cs.auckland.ac.nz/~pgut001/pubs/vista_cost.txt>
<http://www.securityfocus.com/columnists/423>
<http://www.aaxnet.com/editor/edit043.html>
<http://kadaitcha.cx/vista/dogsbreakfast/index.html>
cbfalconer at maineline dot net

--
Posted via a free Usenet account from http://www.teranews.com

May 26 '07 #3

P: n/a
"Shraddha" <sh*************@gmail.comwrote in message
>
What does volatile keyword actually used for?
It means "read this value from memory every time you use it". Normally all
you will achieve is to slow down the computer. However sometimes the
variable might be modified by something outside of the program. Also
occasionally you want to force a memory read for timing purposes.

For instance if we make a loop counter "volatile" then effectively the
compiler cannot optimise the loop away, because it doesn't know how many
times it will need to step through it. So we might have a fairer comparison
of run times.
--
Free games and programming goodies.
http://www.personal.leeds.ac.uk/~bgy1mm

May 26 '07 #4

P: n/a
On Sat, 26 May 2007 19:25:46 +0100, "Malcolm McLean"
<re*******@btinternet.comwrote in comp.lang.c:
"Shraddha" <sh*************@gmail.comwrote in message

What does volatile keyword actually used for?
It means "read this value from memory every time you use it".
[snip]

That's part of what it means, but at least as important is:

Write all modified values to the object, and write them in the order
in which the writes appear in the source.

Consider:

extern volatile unsigned char *Uart_Tx_Register;

void send_char(char ch)
{
if ('\n' == ch)
*Uart_Tx_Register = '\r';
*Uart_Tx_Register = ch;
}

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.club.cc.cmu.edu/~ajo/docs/FAQ-acllc.html
May 27 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.