Volatile variable

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • idkfaidkfaidkfa@gmail.com

    Volatile variable

    I've found this code:

    void function(void) {
    volatile unsigned long * pAdd, *pCntl;
    ........
    for(i = 0, pCntl = &VICPRIORITY 0, pAdd = &VICTADDR0; i < 32; ++i)
    {
    *pCntl++ = *pAdd++ = 0;
    }
    }

    It's the first time that i've found volatile variable: what does it
    mean?if pointers are not declared as volatile, what happens?
    thanks in advance
  • Ian Collins

    #2
    Re: Volatile variable

    idkfaidkfaidkfa @gmail.com wrote:
    It's the first time that i've found volatile variable: what does it
    mean?if pointers are not declared as volatile, what happens?
    What does your text book or a scan through the recent history of this
    group tell you?

    --
    Ian Collins.

    Comment

    • Malcolm McLean

      #3
      Re: Volatile variable


      <idkfaidkfaidkf a@gmail.comwrot e in message
      It's the first time that i've found volatile variable: what does it
      mean?if pointers are not declared as volatile, what happens?
      thanks in advance
      >
      "volatile" means "may be modified/read by something outside of the program",
      and thus the variable is always kept in main memory, never stored in a
      register exept when actually being operated upon.
      This slows down the program. So only use volatile where essential. In the
      nature of things, the modifying program is outside of the competence of C.

      However typically you have interrupt-driven subroutines, for instance to use
      the mouse. An interrupt is generated by a mouse movement, data comes in, and
      is stored in volatile x,y coordinates, and control quickly returned to the
      main thread. Non-interrupt routines can then use the x,y co-ordiantes to
      display the mouse cursor.

      --
      Free games and programming goodies.


      Comment

      • blargg

        #4
        Re: Volatile variable

        In article
        <c889183d-16d6-42b1-ab7c-da7d678241b6@e3 9g2000hsf.googl egroups.com>,
        idkfaidkfaidkfa @gmail.com wrote:
        I've found this code:
        >
        void function(void) {
        volatile unsigned long * pAdd, *pCntl;
        .......
        for(i = 0, pCntl = &VICPRIORITY 0, pAdd = &VICTADDR0; i < 32; ++i)
        {
        *pCntl++ = *pAdd++ = 0;
        }
        }
        >
        It's the first time that i've found volatile variable: what does it
        mean?if pointers are not declared as volatile, what happens?
        thanks in advance
        Actually, pAdd and pCntl are not volatile; what they points to is
        volatile. Very important difference.

        Comment

        Working...