volatile??

This is a discussion on volatile?? within the C Programming forums, part of the General Programming Boards category; what is the difference with unsigned const volatile data; and unsigned volatile data;...

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

    volatile??

    what is the difference with

    unsigned const volatile data;
    and
    unsigned volatile data;

  2. #2
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    Code:
    unsigned const volatile data;
    You can't change the value of 'data', but volatile indicates that something else may change its value.
    Code:
    unsigned volatile data;
    You can change the value of 'data', and volatile indicates that something else may change its value too.
    Code:
    #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
    Posts
    4
    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, 04:38 AM
  3. Replies: 16
    Last Post: 10-29-2006, 04: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, 07:09 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21