Article View: comp.std.c
Article #5545Re: volatile registers (was: The world is not ready for 'volatile')
From: Dennis L. Mumaugh
Date: Wed, 04 Jan 1989 03:52
Date: Wed, 04 Jan 1989 03:52
44 lines
2312 bytes
2312 bytes
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.
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.
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. For example:
volatile int foo;
...
foo = 'H';
foo = 'e';
...
foo = 'd';
foo = '.';
might print "Hello world." on the console of the computer if the
location "foo" were the output port for a device controller.
Without the volatile the compiler or the optimizer is allowed to
reduce the above to
foo = '.';
In this sense the constuct of a "volatile" register doesn't make
sense in the C language as it is not possible to bind a variable
to any specific register [in the instruction set sense].
The question of aliasing is orthoganol to volatile. It just so
happens that the side-effects of declaring a volatile location
result in anti-aliasing of pointers to volatile locations.
--
=Dennis L. Mumaugh
Lisle, IL ...!{att,lll-crg}!cuuxb!dlm OR cuuxb!dlm@arpa.att.com
Technical Details
Message-ID:
<2337@cuuxb.ATT.COM>Path:
arc1-ca.pugleaf.net!utzoo!attcan!uunet!lll-winken!lll-lcc!ames!pacbell!att!cuuxb!dlmReferences:
<141@bms-at.UUCP> <275@twwells.uucp> <15166@mimsy.UUCP> <9236@smoke.BRL.MIL> <15171@mimsy.UUCP> <9316@ihlpb.ATT.COM>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!lll-winken!lll-lcc!ames!pacbell!att!cuuxb!dlm From: dlm@cuuxb.ATT.COM (Dennis L. Mumaugh) Newsgroups: comp.std.c Subject: Re: volatile registers (was: The world is not ready for 'volatile') Summary: volatiler is for kernel hackers only Keywords: volatile Message-ID: <2337@cuuxb.ATT.COM> Date: 4 Jan 89 03:52:18 GMT References: <141@bms-at.UUCP> <275@twwells.uucp> <15166@mimsy.UUCP> <9236@smoke.BRL.MIL> <15171@mimsy.UUCP> <9316@ihlpb.ATT.COM> Reply-To: dlm@cuuxb.UUCP (Dennis L. Mumaugh) Organization: ATT Data Systems Group, Lisle, Ill. Lines: 44