Table Of Contents
Previous Section Next Section

Program 107: Better Trash Collector

We've fixed Program 106 by adding the keyword "volatile." But things still don't work right.

  1 /*************************************************
  2  * clear port -- Clear the input port.           *
  3  *************************************************/
  4 // Input register
  5 const char *volatile in_port_ptr  =
  6         (char *)0xFFFFFFE0;
  7
  8 // Output register
  9 const char *volatile out_port_ptr =
 10         (char *)0xFFFFFFE1;
 11
 12 /***********************************************
 13  * clear_input -- Clear the input device by    *
 14  *      reading enough characters to empty the *
 15  *      buffer. (It doesn't matter if we read  *
 16  *      extra, just so long as we read enough.)*
 17  ***********************************************/
 18 void clear_input(void)
 19 {
 20     char ch;     // Dummy character
 21
 22     ch = *in_port_ptr;   // Grab data
 23     ch = *in_port_ptr;   // Grab data
 24     ch = *in_port_ptr;   // Grab data 25 }

(Next Hint 336. Answer 61.)

Table Of Contents
Previous Section Next Section