Volatile variable

  • Follow


I've found this code:

void function(void) {
volatile unsigned long * pAdd, *pCntl;
........
  for(i = 0,  pCntl = &VICPRIORITY0, 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
0
Reply idkfaidkfaidkfa (13) 9/27/2008 7:11:16 AM

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.
0
Reply ian-news (9874) 9/27/2008 7:15:32 AM


<idkfaidkfaidkfa@gmail.com> wrote 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.
http://www.personal.leeds.ac.uk/~bgy1mm

0
Reply regniztar (3128) 9/27/2008 10:48:54 AM

In article
<c889183d-16d6-42b1-ab7c-da7d678241b6@e39g2000hsf.googlegroups.com>,
idkfaidkfaidkfa@gmail.com wrote:

> I've found this code:
> 
> void function(void) {
> volatile unsigned long * pAdd, *pCntl;
> .......
>   for(i = 0,  pCntl = &VICPRIORITY0, 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.
0
Reply blargg.h4g (301) 9/27/2008 7:38:04 PM

3 Replies
30 Views

(page loaded in 0.086 seconds)


Reply: