home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.std.c
- Path: sparky!uunet!twwells!bill
- From: bill@twwells.com (T. William Wells)
- Subject: void expressions and volatile types
- Organization: None, Mt. Laurel, NJ
- Message-ID: <BtnI48.D9I@twwells.com>
- Date: Thu, 27 Aug 1992 16:36:04 GMT
- Lines: 32
-
- Certain contexts, the left operand of the comma operator,
- expression statements, and the first and third expressions of a
- for statement, are designated as void expressions. (I'd assume
- that the operand of a cast to void is also.) A void expression is
- defined as one where the value of the expression is discarded. The
- key is the word "discarded". This implies that the value is
- computed but then ignored.
-
- The problem is then what to do with statements like a; and a=b;
- when a is a volatile object. The first expression accesses a but
- then discards the value, which is fine. The other does NOT do
- what you'd expect, though. The reason is that the assignment has a
- value which is the value of a after the assignment, which can only
- be obtained by accessing a. Thus a=b results in a sequence like:
-
- load b
- store a
- load a
-
- rather than the intended load and store.
-
- I personally would prefer the other interpretation, in which a
- void expression is, as the standard _also_ says, evaluated only
- for its side effects. Otherwise, one would have serious problems
- using volatile for device registers. (This would have the effect
- that a; doesn't actually reference a because no value is computed
- but I think that that is a legitimate action. (int)a; would force
- the access anyway.)
-
- ---
- Bill { uunet | decwrl | telesci }!twwells!bill
- bill@twwells.com
-