Thread: volatile??

  1. #1
    Registered User jacktibet's Avatar
    Join Date
    Mar 2003


    what is the difference with

    unsigned const volatile data;
    unsigned volatile data;

  2. #2
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    unsigned const volatile data;
    You can't change the value of 'data', but volatile indicates that something else may change its value.
    unsigned volatile data;
    You can change the value of 'data', and volatile indicates that something else may change its value too.
    #include <stdio.h>
    int main(void)
       unsigned const volatile a = 1; /* initialization, ok */
       unsigned       volatile b = 1; /* initialization, ok */
       a = 4; /* assignment, error - 'cannot modify a const object' */
       b = 5; /* assignment, ok */
       while(a && b)
          printf("a = %u, b = %u\n", a, b);
       return 0;
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  3. #3
    Registered User
    Join Date
    May 2003
    A lot of uses of "volatile" are with systems that interface directly to hardware, where they're talking to something other than RAM, like a device control register. So, to answer your question, the difference between the 2 is that the "const" means you're accessing a read-only memory address.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Multithreading (flag stopping a thread, ring buffer) volatile
    By ShwangShwing in forum C Programming
    Replies: 3
    Last Post: 05-19-2009, 07:27 AM
  2. strange grammar about volatile and operator overload
    By George2 in forum C++ Programming
    Replies: 6
    Last Post: 01-30-2008, 05:38 AM
  3. Replies: 16
    Last Post: 10-29-2006, 05:04 AM
  4. volatile int address ??
    By pprabhakar in forum C Programming
    Replies: 2
    Last Post: 05-14-2006, 01:37 PM
  5. volatile keyword help!!!!
    By penney in forum Linux Programming
    Replies: 2
    Last Post: 03-12-2003, 08:09 AM