home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / std / c / 2352 < prev    next >
Encoding:
Internet Message Format  |  1992-07-21  |  1.0 KB

  1. From: boyne@hplvec.LVLD.HP.COM (Art Boyne)
  2. Date: Mon, 20 Jul 1992 14:55:05 GMT
  3. Subject: Re: volatile qualifier
  4. Message-ID: <720001@hplvec.LVLD.HP.COM>
  5. Organization: Hewlett-Packard Co., Loveland, CO
  6. Path: sparky!uunet!usc!elroy.jpl.nasa.gov!sdd.hp.com!hpscdc!hplextra!hpfcso!hplvec!boyne
  7. Newsgroups: comp.std.c
  8. References: <1200@datmuc.UUCP>
  9. Lines: 17
  10.  
  11. One caveat, though, regarding volatile.  The ANSI standard does not
  12. impose any particular implementation on how the compiler handles
  13. volatile.  And one very well-known PC-based compiler has a rather
  14. stupid definition.  Given then code segment:
  15.  
  16.     #define device_register (*(volatile int*)12345)    /* some address */
  17.     #define MASK 0x400
  18.  
  19.     if (device_register & MASK)
  20.         ...
  21.  
  22. the compiler, realizing that MASK only affects the upper byte of the
  23. 16-bit device register, "optimizes" the register access, and does
  24. an 8-bit access.  Now it just happens that the hardware only supports
  25. 16-bit access and gives a bus error on 8-bit access....
  26.  
  27. Art Boyne, boyne@hplvla.lvld.hp.com
  28.