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