| ??? 07/13/07 13:02 Read: times |
#141852 - Ok, visualize this one Responding to: ???'s previous message |
OK I see (roughly) HOW it works if a variable is declared volatile, but what is it good for, then?
Ok, visualize this one: if (Ralph == 1)
{
....
}
else if (Ralph == 2)
{
....
}
// here an ISR changes Ralph from 4 to 1
else if (Ralph == 3)
{
....
}
else if (Ralph == 4)
{
....
}no amount of applying volatile will help here, the only possible way is to use a local copy of Ralph.
now, visualize this one: if (flag)
{
....
}the compiler is fully justified in copying flag to a register and testing it there forever if flag is not declared volatile.
SO 'volatile' does good when you know when to use it and when not Erik |
| Topic | Author | Date |
| more to atomicity and such | 01/01/70 00:00 | |
| Interesting example ... | 01/01/70 00:00 | |
| which I did | 01/01/70 00:00 | |
| Aside: Keil - Atomic functions | 01/01/70 00:00 | |
| If you can afford it. | 01/01/70 00:00 | |
| volatile | 01/01/70 00:00 | |
| does this have some formal definition? | 01/01/70 00:00 | |
| sequence points and side effects | 01/01/70 00:00 | |
| what's exactly the value of volatile, then? | 01/01/70 00:00 | |
| example | 01/01/70 00:00 | |
| bu what is it good for then? | 01/01/70 00:00 | |
| Ok, visualize this one | 01/01/70 00:00 | |
| within a loop | 01/01/70 00:00 | |
| Memory Mapped I/O | 01/01/70 00:00 | |
OK I see it now, thanks. | 01/01/70 00:00 | |
| volatile switch | 01/01/70 00:00 |



