#: 3235 S12/OS9/68000 (OSK)
03-May-90 06:18:24
Sb: #3232-C process control
Fm: James Jones 76257,562
To: Joseph W. Cheek 76264,142 (X)
What he's talking about is one of the so-called "type qualifiers" that are part
of the recently-adopted ANSI C standard. The "volatile" qualifier is intended
to force the compiler to *not* do certain kinds of optimization, which aren't
appropriate for, to use the standard example, memory-mapped I/O stuff.
Example: if one has a busy-wait loop of the form
while (*p == 0) ;
an optimizing compiler would be within its rights to peform code motion on the
apparently unchanging value of *p and transform the code into
if (*p == 0) {for (;;) ;}
testing *p only once. In ANSI C, if p were declared to have the type "pointer
to volatile int," the compiler would be informed that unknown external events
could change the value of *p, so that it is improper to consider *p as not
changing, even though the code contains nothing that would change it.
|