volatile?

Discussion in 'C Programming' started by Rick, Oct 14, 2003.

  1. Rick

    Rick Guest

    Hi,

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

    Rick
    Rick, Oct 14, 2003
    #1
    1. Advertising

  2. 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
    Allin Cottrell, Oct 14, 2003
    #2
    1. Advertising

  3. "Rick" <rrquick@nospam-com> wrote in message
    news:3f8b6961$...
    > 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/articles/pathak/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.
    Vijay Kumar R Zanvar, Oct 14, 2003
    #3
  4. 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:

    .

    Regards
    --
    Irrwahn
    ()
    Irrwahn Grausewitz, Oct 14, 2003
    #4
  5. Rick

    Randy Howard Guest

    In article <bmgblj$lvb3o$-berlin.de>,
    says...
    > You can find good information about volatile here:
    >
    > http://www.programmersheaven.com/articles/pathak/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:
    Randy Howard, Oct 21, 2003
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Knute Johnson

    Re: Volatile?

    Knute Johnson, Jul 1, 2003, in forum: Java
    Replies:
    17
    Views:
    1,434
    Knute Johnson
    Jul 3, 2003
  2. Doug Pardee

    Re: Volatile?

    Doug Pardee, Jul 1, 2003, in forum: Java
    Replies:
    0
    Views:
    882
    Doug Pardee
    Jul 1, 2003
  3. Replies:
    1
    Views:
    901
    Knute Johnson
    Aug 29, 2003
  4. Daniel

    Can volatile be trusted?

    Daniel, Sep 11, 2003, in forum: Java
    Replies:
    7
    Views:
    465
    Chris Uppal
    Sep 12, 2003
  5. ben
    Replies:
    5
    Views:
    579
    Ulrich Eckhardt
    Jan 11, 2005
Loading...

Share This Page