Mail Archives: djgpp/1997/08/11/01:33:53
On Wed, 6 Aug 1997, Korenschi Francisc Eduard wrote:
> Hi,
>
>
> I know it sounds crazy, but what does the 'voltaile' with a
> variable/function ?
>
>
> Thanx for bothering,
> Eduard
The 'volatile' keyword is a message to the compiler that it can't make any
assumptions about the value of variable when optimizing the code. This is
usually because the variable might be changed by an interrupt handler or
hardware, or something else that the compiler could never know about.
Therefore, everytime you use the variable in your code the compiler
explicitly loads it from memory, instead of assuming that the value is
stored in a register becuase it used it in your last line of code.
'volatile' means nothing to a function, and you should probably be
getting a warning if you compile with -Wall. It can be useful with asm
statements in C/C++ code, because it tells the compiler not to move the
code when it optimizes, which it is otherwise free to do.
---------------
Peter Berdeklis
Dept. of Physics, Univ. of Toronto
- Raw text -