Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!think.com!compass!worley From: worley@compass.com (Dale Worley) Newsgroups: comp.lang.c Subject: Re: const and volatile Message-ID: Date: 21 May 91 14:38:59 GMT References: <1991May17.213923.17879@ready.eng.ready.com> Sender: root@compass.com Organization: Compass, Inc., Wakefield, MA, U.S.A. Lines: 33 In-reply-to: dhoward@ready.eng.ready.com's message of 17 May 91 21:39:23 GMT In article <1991May17.213923.17879@ready.eng.ready.com> dhoward@ready.eng.ready.com (David Howard) writes: I declare: const unsigned char *device = (unsigned char *)0x600000b; Then I do: *device = 0x01; The compiler complains: 'attempt to modify a const' what I want is for the pointer to be const, but not what it points to! Say: "unsigned char * const device = ...;" Obvious, isn't it? :-) If I declare the pointer: volatile unsigned char *device = 0x600000e; the compiler treats BOTH the pointer and pointee as volatile. By that I mean, when I use the pointer, the compiler always reloads the pointer itself, and also always reaccesses the dereferenced location. In this case it works OK, but generates extra code to reload the pointer with 0x600000e every time I use it. The compiler is conforming, but it is wasting effort. Hope that the next version of the compiler is more efficient. Dale Worley Compass, Inc. worley@compass.com -- Conspiracy is the opiate of the asses.