[comp.lang.c] const pointers

bvs@light.uucp (Bakul Shah) (04/04/88)

In article <1988Apr3.013733.28401@utzoo.uucp> henry@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

henry@utzoo.uucp (Henry Spencer) (04/06/88)

> >               ...              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...
> 
> Huh?  If by `it' you mean the object pointed to by the const pointer,
> your intepretation seems wrong...

Combination of bad wording on my part and a misunderstanding on yours:
I'm talking about "const foo *", which is the *useful* form of const
pointer, whereas you're thinking of "foo *const".

(Actually, before I get flamed on this, I'll concede that "foo *const"
has uses... small ones, insufficient to justify its addition to the
language in my opinion.)
-- 
"Noalias must go.  This is           |  Henry Spencer @ U of Toronto Zoology
non-negotiable."  --DMR              | {allegra,ihnp4,decvax,utai}!utzoo!henry