Find the answer to your Linux question:
Results 1 to 4 of 4
Hi, i like to know the importance of constant volatile in device drivers or some where. Fews doubt on this Keyword:If the volatile variable is constant, then what is the ...
  1. #1
    Just Joined!
    Join Date
    Nov 2006
    Location
    Hyderabad
    Posts
    85

    const volatile

    Hi,

    i like to know the importance of constant volatile in device drivers or some where.
    Fews doubt on this Keyword:If the volatile variable is constant, then what is the use.
    It has been made volatile, since it can be modified on the fly in some other thread.
    If it can be made constant, then volatile will not carry any meaning!

    thanx in advance

  2. #2
    Linux Engineer wje_lf's Avatar
    Join Date
    Sep 2007
    Location
    Mariposa
    Posts
    1,192
    It is possible for memory-mapped hardware to be designed so that if you read a particular location in "memory", then some hardware action will be performed. The const is a way of documenting that there is no reason to change the value itself. The volatile is a way of ensuring that no matter how much your compiler optimizes the code, a reference in a C program to that location will not be "optimized out"; that is, it will always be compiled as a real reference to that location.

    Hope this helps.

  3. #3
    Just Joined!
    Join Date
    Nov 2006
    Location
    Hyderabad
    Posts
    85
    thank you for reply

    i gone for some searching on const volatile variable.

    if we declare volatile variable as const, it cann't be changed by current context, but it can be changed by external events such as signal interrupts, hardware registers,memory mapped i/o.

  4. #4
    Linux Engineer wje_lf's Avatar
    Join Date
    Sep 2007
    Location
    Mariposa
    Posts
    1,192
    Oops, forgot about that. I got an education today, thanks!

Posting Permissions

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