Article View: comp.std.c
Article #5554Re: volatile registers
From: The Beach Bum
Date: Thu, 05 Jan 1989 17:03
Date: Thu, 05 Jan 1989 17:03
54 lines
2499 bytes
2499 bytes
In article <2337@cuuxb.ATT.COM> dlm@cuuxb.UUCP (Dennis L. Mumaugh) writes:
>In article <9316@ihlpb.ATT.COM> nevin1@ihlpb.UUCP
>(55528-Liber,N.J.) makes some comments about volatile that seem
>to reflect many people's understanding.
>
>The concept "volatile" should not occur in any general C program.
>This feature exists only for the stand alone, the real time and
>the kernel hacker.
This is becoming increasing less and less true. Shared memory
has many applications which should be exploited.
>Its purpose is to state that each and every reference to the
>volatile object [location, structure, register, or whatever] is
>necessary and not to optimize such references in any way.
Enough said. Let the programmer beware.
>Its only use in a UNIX environment *should* be with respect to
>shared memory or mmaped files where more than once process may
>access the same location "simultaneously". I have seen its need
>only in writing drivers where a location actually maps to a
>device register and each referrence to the location actually
>results in the device doing something.
A common usage is in interrupt [ software ] handlers where the
signal catching routine sets a flag and returns.
The proper definition for such a flag should be
in catch.c:
--
int sigflag;
int catch (sig)
{
...
sigflag = 1;
...
}
--
then outside catch.c you must use
extern volatile int sigflag;
I am wondering how many programs will get this right when the
ANSI compilers invade our lives. Or, how many program get
it right NOW? I bet the number is virtually identical ...
--
John F. Haugh II +-Quote of the Week:-------------------
VoiceNet: (214) 250-3311 Data: -6272 |"Anything on the road which can be
InterNet: jfh@rpp386.Dallas.TX.US | hit, will be ..."
UucpNet : <backbone>!killer!rpp386!jfh +--------------------------------------
Technical Details
Message-ID:
<10720@rpp386.Dallas.TX.US>Path:
arc1-ca.pugleaf.net!utzoo!attcan!uunet!lll-winken!lll-ncis!helios.ee.lbl.gov!pasteur!ames!killer!vector!rpp386!jfhReferences:
<141@bms-at.UUCP> <275@twwells.uucp> <15166@mimsy.UUCP> <9236@smoke.BRL.MIL> <15171@mimsy.UUCP> <9316@ihlpb.ATT.COM> <2337@cuuxShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!lll-winken!lll-ncis!helios.ee.lbl.gov!pasteur!ames!killer!vector!rpp386!jfh From: jfh@rpp386.Dallas.TX.US (The Beach Bum) Newsgroups: comp.std.c Subject: Re: volatile registers Message-ID: <10720@rpp386.Dallas.TX.US> Date: 5 Jan 89 17:03:43 GMT References: <141@bms-at.UUCP> <275@twwells.uucp> <15166@mimsy.UUCP> <9236@smoke.BRL.MIL> <15171@mimsy.UUCP> <9316@ihlpb.ATT.COM> <2337@cuux Reply-To: jfh@rpp386.Dallas.TX.US (The Beach Bum) Organization: Big "D" Home for Wayward Hackers Lines: 54