On (09 Aug 97) Gerry Danen wrote to Darin Mcbride...
GD> I've never used volatile on any direct screen I/O. Perhaps that's
GD> because under single-tasking DOS that's not a problem.
It has more to do with the compiler than the OS, as a rule. For
instance, if I take code like this:
#include
int main(void) {
int _far *screen = (int _far *)MK_FP(0xb800, 0);
for ( int i=0; i<(80*25); i++)
*screen++ = ' ';
return 0;
}
I intend that it clear the screen. As long as I compile without
optimization, it does exactly that. _However_ if I tell Microsoft VC++
1.52 to use maximum optimization, it does absolutely _nothing_.
The problem is that the compiler has "noticed" that I'm not "using" any
of the values I write into `*screen', so it simply doesn't write them
there anymore. If I change the declaration of `screen' to:
int _far volatile *screen /* ... */;
It clears the screen regardless of the level of optimization I decide to
use.
(disclaimer: this is demo code only. It't not intended for real use.
It definitely _won't_ work if you have a monochrome card installed. If
you have a color card installed, it's likely to cause a nuclear
catastrophe.)
Later,
Jerry.
... The Universe is a figment of its own imagination.
--- PPoint 1.90
---------------
* Origin: Point Pointedly Pointless (1:128/166.5)
|