home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / std / c / 2529 < prev    next >
Encoding:
Text File  |  1992-08-27  |  1.6 KB  |  42 lines

  1. Newsgroups: comp.std.c
  2. Path: sparky!uunet!twwells!bill
  3. From: bill@twwells.com (T. William Wells)
  4. Subject: void expressions and volatile types
  5. Organization: None, Mt. Laurel, NJ
  6. Message-ID: <BtnI48.D9I@twwells.com>
  7. Date: Thu, 27 Aug 1992 16:36:04 GMT
  8. Lines: 32
  9.  
  10. Certain contexts, the left operand of the comma operator,
  11. expression statements, and the first and third expressions of a
  12. for statement, are designated as void expressions. (I'd assume
  13. that the operand of a cast to void is also.) A void expression is
  14. defined as one where the value of the expression is discarded. The
  15. key is the word "discarded". This implies that the value is
  16. computed but then ignored.
  17.  
  18. The problem is then what to do with statements like a; and a=b;
  19. when a is a volatile object. The first expression accesses a but
  20. then discards the value, which is fine. The other does NOT do
  21. what you'd expect, though. The reason is that the assignment has a
  22. value which is the value of a after the assignment, which can only
  23. be obtained by accessing a. Thus a=b results in a sequence like:
  24.  
  25.     load b
  26.     store a
  27.     load a
  28.  
  29. rather than the intended load and store.
  30.  
  31. I personally would prefer the other interpretation, in which a
  32. void expression is, as the standard _also_ says, evaluated only
  33. for its side effects. Otherwise, one would have serious problems
  34. using volatile for device registers. (This would have the effect
  35. that a; doesn't actually reference a because no value is computed
  36. but I think that that is a legitimate action. (int)a; would force
  37. the access anyway.)
  38.  
  39. ---
  40. Bill                            { uunet | decwrl | telesci }!twwells!bill
  41. bill@twwells.com
  42.