home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / std / c / 2584 < prev    next >
Encoding:
Internet Message Format  |  1992-09-08  |  1.7 KB

  1. Path: sparky!uunet!mcsun!uknet!acorn!ixi!clive
  2. From: clive@x.co.uk (Clive Feather)
  3. Newsgroups: comp.std.c
  4. Subject: Re: void expressions and volatile types
  5. Message-ID: <1992Sep07.104043.19879@x.co.uk>
  6. Date: 7 Sep 92 10:40:43 GMT
  7. References: <BtnI48.D9I@twwells.com>
  8. Organization: IXI Limited, Cambridge, UK
  9. Lines: 30
  10.  
  11. In article <BtnI48.D9I@twwells.com> bill@twwells.com (T. William Wells) writes:
  12. > The problem is then what to do with statements like a; and a=b;
  13. > when a is a volatile object. The first expression accesses a but
  14. > then discards the value, which is fine. The other does NOT do
  15. > what you'd expect, though. The reason is that the assignment has a
  16. > value which is the value of a after the assignment, which can only
  17. > be obtained by accessing a. Thus a=b results in a sequence like:
  18. >
  19. >    load b
  20. >    store a
  21. >    load a
  22. >
  23. > rather than the intended load and store.
  24.  
  25. Here's the mistake. The value of the expression can be obtained by
  26. remembering the value stored into a - it is not necessary to re-fetch
  27. it, even though a is volatile.
  28.  
  29. The storing of a value into a is a side-effect, and so takes place
  30. sometime before the next sequence point. Any other change that takes
  31. place to a (e.g. because it is a memory-mapped device) between the same
  32. pair of sequence points counts as a double assignment, and is therefore
  33. undefined, and therefore the implementation can do what it wants
  34. (including not reading a after storing).
  35.  
  36. -- 
  37. Clive D.W. Feather     | IXI Limited         | If you lie to the compiler,
  38. clive@x.co.uk          | 62-74 Burleigh St.  | it will get its revenge.
  39. Phone: +44 223 462 131 | Cambridge   CB1 1OJ |   - Henry Spencer
  40. Fax:   +44 223 462 132 | United Kingdom      |
  41.