const and volatile
Dale Worley
worley at compass.com
Wed May 22 00:38:59 AEST 1991
In article <1991May17.213923.17879 at ready.eng.ready.com> dhoward at 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 at compass.com
--
Conspiracy is the opiate of the asses.
More information about the Comp.lang.c
mailing list