const pointers

Bakul Shah bvs at light.uucp
Tue Apr 5 02:20:18 AEST 1988


In article <1988Apr3.013733.28401 at utzoo.uucp> henry at utzoo.uucp (Henry Spencer) writes:
>
>               ...              const on a pointer does not mean that the
>thing pointed to is constant, just that attempts to modify it through that
							    ^^
>pointer are illegal.  (If this double meaning of const strikes you as less
>than ideal, you're in good company.)

Huh?  If by `it' you mean the object pointed to by the const pointer,
your intepretation seems wrong (or I have misunderstood you or the
draft).

To manipulate an object at a fixed known location, we used to have to
play games like
	#define ioreg   ((long *)0x4000004)
Instead, now we can say
	long * const ioreg = (long *)0x4000004;
As I understand it, here `ioreg' is a const and `*ioreg' is a variable.

In both cases
	*ioreg = 5;
is legal, and
	ioreg = (long *)0x1234;
is flagged by the compiler as illegal, which is exactly the effect one
wants.

I don't see a double meaning; perhaps you'd like to elaborate?
-- 
Bakul Shah

..!{ucbvax,sun}!amdcad!light!bvs



More information about the Comp.lang.c mailing list