🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #3016

Re: Assignment operator and volatile

#3016
From: Chris Torek
Date: Mon, 14 Dec 1992 02:16
36 lines
1626 bytes
In article <1992Dec13.215752.29143@softway.sw.oz.au>
peterc@suite.sw.oz.au (Peter Chubb) writes:
>#define	ap	((volatile char *)0x1234)
>	*ap = *ap = 1;

(Side issue: I would be much happier with this if it were, e.g.,

	char v;
	v = *ap = 1;

so that there are not two independent writes to *ap without an
intervening sequence point.  Ignoring that issue:)

>(where the char at 0x1234 may be write-only, and return garbage when read,)
>should a strictly conforming compiler generate a read instruction
>after its write instruction, or can it assume that immediately after
>the assignment, the char has the value 1?

My own interpretation is that the compiler can do as it pleases, but
must document what it does.

>	I.e., in 68000 code, 
>
>	move.l	#$1234,a0
>	move.b	#1,d0
>	move.b	d0,(a0)
>	move.b	(a0),d0	<-- Is this instruction necessary?
>	move.b	d0,(a0)

I believe this would be a valid translation both with and without
the marked line, given appropriate compiler documentation.

(Incidentally, GCC apparently uses the `re-read' interpretation.)
-- 
In-Real-Life: Chris Torek, Lawrence Berkeley Lab CSE/EE (+1 510 486 5427)
Berkeley, CA		Domain:	torek@ee.lbl.gov
Technical Details
Message-ID: <27964@dog.ee.lbl.gov>
Path: arc1-ca.pugleaf.net!sparky!uunet!think.com!ames!agate!dog.ee.lbl.gov!horse.ee.lbl.gov!torek
References: <1992Dec13.215752.29143@softway.sw.oz.au>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!think.com!ames!agate!dog.ee.lbl.gov!horse.ee.lbl.gov!torek
From: torek@horse.ee.lbl.gov (Chris Torek)
Newsgroups: comp.std.c
Subject: Re: Assignment operator and volatile
Date: 14 Dec 1992 02:16:35 GMT
Organization: Lawrence Berkeley Laboratory, Berkeley CA
Lines: 36
Message-ID: <27964@dog.ee.lbl.gov>
References: <1992Dec13.215752.29143@softway.sw.oz.au>
NNTP-Posting-Host: 128.3.112.15