Find the answer to your Linux question:
Results 1 to 3 of 3
Dear All, Please can any one provide some information on real-time applications of CONST and VOLATILE CONSTANT qualifers. Regards, Sri Anu....
  1. #1
    Just Joined!
    Join Date
    May 2009
    Posts
    11

    C Qualifiers

    Dear All,

    Please can any one provide some information on real-time applications of CONST and VOLATILE CONSTANT qualifers.

    Regards,
    Sri Anu.

  2. #2
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
    Posts
    8,974
    In general, const means that the variable is a constant - you cannot modify it. A volatile constant means that the variable can change between reads, but only by an external force (the kernel, for example). An example of a volatile constant could be something like the CPU temperature. The kernel monitors that, and if you had an external reference to that variable, it could change, even while you read it. But YOU could not change it in your code.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  3. #3
    Trusted Penguin Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,230
    On a lower level, "volatile" tells the compiler not to store the variable in a register. This is because, as Rubberman said, it can change due to factors outside of your own code.

    As for "const", on its simplest, it is as Rubberman says: you cannot modify the variable. However, it gets a bit more difficult when pointers get involved:
    Code:
    int *number; # normal
    int * const number; # The value stored at number (*number) can change, but number itself may not
    int const *number;  # The value stored at number (*number) may not change, but number may
    int const * const number; # number can neither be reassigned nor have the value it points to be changed
    I hope that helps.
    DISTRO=Arch
    Registered Linux User #388732

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...