abt volatile variable

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • karunakar
    New Member
    • Aug 2007
    • 1

    abt volatile variable

    hi,


    this is karunakar.My question is "when u declared a variable as volatile ,where the variable will stored(i mean, which memory part (section) is assigned for that ) ".
  • Meetee
    Recognized Expert Contributor
    • Dec 2006
    • 928

    #2
    Originally posted by karunakar
    hi,


    this is karunakar.My question is "when u declared a variable as volatile ,where the variable will stored(i mean, which memory part (section) is assigned for that ) ".
    Hi,

    Volatile qualifiers can be used to change the behavior of a type.

    volatile int i = 5; declares and initializes an object with type volatile int whose value will be always read from memory. A variable or object declared with the volatile
    keyword may be modified externally from the declaring object.

    Regards

    Comment

    • gsi
      New Member
      • Jul 2007
      • 51

      #3
      Hi,
      Following the above explanation, Volatile is a type qualifier and not a storage class specifier ( like ' register ' which requests the compiler to allocate the variable qualified with 'register' in a cpu register). So it has nothing to do with the section of memory in to which it will be allocated but rather tells the compiler not to perform any optimization on the variable (Hence they are always read from memory on each reference to it).

      thanks,
      gsi.

      Comment

      Working...