Gianluca Moro
Guest
|
Posted:
Mon Dec 06, 2004 8:44 pm Post subject:
volatile attribute |
|
|
Hi,
the volatile attribute is an indication that the variable can change
for example on account of an interrupt.
With this indication the compiler cannot use a register to store the variable,
or do any type of optimization.
For example if a volatile variable is not used, the compiler do not
remove it, as it could be used by an interrupt
bye
giammy |
|
Mark A. Odell
Guest
|
Posted:
Tue Dec 07, 2004 1:13 am Post subject:
Re: volatile attribute |
|
|
giangiammy@yahoo.com (Gianluca Moro) wrote in
news:dbacaf5c.0412060744.729db90e@posting.google.com:
| Quote: | the volatile attribute is an indication that the variable can change
for example on account of an interrupt.
|
Volatile is a keyword in C.
Or when you create a pointer to a volatile "thing" that is, in fact,
memory mapped hardware. If the hardware updates the "thing" and the
compiler knows the variable is volatile then things should work as you
expect. This is not a requirement of ISO C which specifies the behavior of
volatile variables in a very restricted way.
| Quote: | With this indication the compiler cannot use a register to store the
variable, or do any type of optimization.
|
No, it can use a register but it must reload the register with the source
location every time you access the volatile variable.
| Quote: | For example if a volatile variable is not used, the compiler do not
remove it, as it could be used by an interrupt
|
That's a consequence of volatile.
--
- Mark ->
-- |
|