??? 05/20/08 13:16 Read: times |
#154965 - put simply... Responding to: ???'s previous message |
The variables you declare in C live in ram. In order to do operations on a given variable, the value is read from ram into a processor register, processed then written back to ram. In order to speed execution, the compiler can optimise the code whereby it can save the variable in a register and keep it there to do a number of operations on it, then write it back to ram. This is not a problem usually, but where you might have an interrupt service routine using that same variable, it will read the value from ram but in the meantime the variable's value is in a processor register and has been modified so the interrupt code will not see the same value. Therefore the 'volatile' modifier tells the compiler not to do certain optimisations that might cause problems and to always save the value back to ram for each operation on that variable. Another instance of compiler optimisations is removal of code that does (seemingly) nothing. An example is a for loop used for a time delay. The compiler might decide this does nothing useful and eliminates it - using the volatile modifier on the loop variable forces the compiler to actually implement the code ratherthan optimise it away. Is there anything specific you don't understand now? |
Topic | Author | Date |
keyword volatile | 01/01/70 00:00 | |
Opposite! | 01/01/70 00:00 | |
volatile modifier | 01/01/70 00:00 | |
Incorrect | 01/01/70 00:00 | |
incorrect! | 01/01/70 00:00 | |
even more | 01/01/70 00:00 | |
A heap o' trouble | 01/01/70 00:00 | |
the curse of the PC programmers | 01/01/70 00:00 | |
meaning of "volatile" with example | 01/01/70 00:00 | |
example | 01/01/70 00:00 | |
gobbelygook | 01/01/70 00:00 | |
heap? | 01/01/70 00:00 | |
Confused? | 01/01/70 00:00 | |
Google told me... | 01/01/70 00:00 | |
link | 01/01/70 00:00 | |
go through my explanation | 01/01/70 00:00 | |
put simply... | 01/01/70 00:00 | |
thanks | 01/01/70 00:00 | |
answer accepted by interviewer | 01/01/70 00:00 | |
Not entirely | 01/01/70 00:00 | |
not input only | 01/01/70 00:00 | |
That's the kind of thing I'd be looking for...![]() | 01/01/70 00:00 |