Home     |     .Net Programming    |     cSharp Home    |     Sql Server Home    |     Javascript / Client Side Development     |     Ajax Programming

Ruby on Rails Development     |     Perl Programming     |     C Programming Language     |     C++ Programming     |     IT Jobs

Python Programming Language     |     Laptop Suggestions?    |     TCL Scripting     |     Fortran Programming     |     Scheme Programming Language


 
 
Cervo Technologies
The Right Source to Outsource

MS Dynamics CRM 3.0

C Programming Language

Volatile?


What does volatile keyword actually used for?
Shraddha skrev:
> What does volatile keyword actually used for?

http://publications.gbdirect.co.uk/c_book/chapter8/const_and_volatile...

nice explanation

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

"Shraddha" <shraddhajosh@gmail.com> wrote 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

On Sat, 26 May 2007 19:25:46 +0100, "Malcolm McLean"
<regniz@btinternet.com> wrote in comp.lang.c:

> "Shraddha" <shraddhajosh@gmail.com> wrote 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
Add to del.icio.us | Digg this | Stumble it | Powered by Megasolutions Inc