🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #1172

Re: void expressions and volatile types

#1172
From: Clive Feather
Date: Mon, 07 Sep 1992 10:40
30 lines
1734 bytes
In article <BtnI48.D9I@twwells.com> bill@twwells.com (T. William Wells) writes:
> 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.

Here's the mistake. The value of the expression can be obtained by
remembering the value stored into a - it is not necessary to re-fetch
it, even though a is volatile.

The storing of a value into a is a side-effect, and so takes place
sometime before the next sequence point. Any other change that takes
place to a (e.g. because it is a memory-mapped device) between the same
pair of sequence points counts as a double assignment, and is therefore
undefined, and therefore the implementation can do what it wants
(including not reading a after storing).

-- 
Clive D.W. Feather     | IXI Limited         | If you lie to the compiler,
clive@x.co.uk          | 62-74 Burleigh St.  | it will get its revenge.
Phone: +44 223 462 131 | Cambridge   CB1 1OJ |   - Henry Spencer
Fax:   +44 223 462 132 | United Kingdom      |
Technical Details
Message-ID: <1992Sep07.104043.19879@x.co.uk>
Path: arc1-ca.pugleaf.net!sparky!uunet!mcsun!uknet!acorn!ixi!clive
References: <BtnI48.D9I@twwells.com>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!mcsun!uknet!acorn!ixi!clive
From: clive@x.co.uk (Clive Feather)
Newsgroups: comp.std.c
Subject: Re: void expressions and volatile types
Message-ID: <1992Sep07.104043.19879@x.co.uk>
Date: 7 Sep 92 10:40:43 GMT
References: <BtnI48.D9I@twwells.com>
Organization: IXI Limited, Cambridge, UK
Lines: 30