Is your system polluted?
Robert Swirsky
swirsky at olivee.olivetti.com
Wed Dec 27 03:59:57 AEST 1989
There's another place where the volatile keyword is useful--if there's
a variable whose value is set in an interrupt service routine.
Many Cs (e.g., Microsoft's C for Unix) have an interrupt keyword so that
a function saves all its registers and ends with an IRET.
If the compiler does invarient code optimization, it can incorrectly
see code as invarient without the "volatile" keyword. For example:
do {
/* blah blah blah */
} while (flag==0);
If "flag" is set in an interrupt service routine, some compilers would
move the test for flag being zero out of the loop, because no statement
within the loop changes its value. The result is a loop that never exits.
I've seen this happen with MSC for DOS...
"All opinions are my own, and may not be those of my employer."
More information about the Comp.unix.wizards
mailing list