[comp.std.c] Assignment compatibility

john@acorn.co.uk (John Bowler) (09/21/89)

As far as I can see, in the fragment:-

{
	const void **cptr;
	void **ptr;

	...
	cptr = ptr;
	...
}

The assignment is non-conforming, because a constraint on the
assignment operator is violated; section 3.3.16.1:-

 ``One of the following shall hold:

   ...
   o both operands are pointers to qualified or unqualified versions
     of compatible types, and the type pointed to by the left has all
     the qualifiers of the type pointed to by the right.''

and (section 3.5.3):-

 ``For two qualified types to be compatible, both shall have the identically
   qualified version of a compatible type''

so ``const void *'' is NOT compatible with ``void *'' (well, it isn't totally
clear - ``void *'' is not qualified...) and therefore an expression of the
form:-

	(const void **) = (void **)

is not allowed.  Is this correct?  If so, why; I can assign a (void *) to
a (const void *), but not a (void **) to a (const void **), despite the
fact that I can do nothing with a (const void **) which I could not do
with a (void **)!  In particular, the values which I can assign to
*cptr (type (const void **)) are a subset of the values which I can
assign to *ptr (void **).  (Anything which I can assign to *cptr, I can
also validly assign to *ptr).

John Bowler (jbowler@acorn.co.uk)