Is this a valid ANSI program?

Dale Worley worley at compass.com
Fri Jun 28 00:57:40 AEST 1991


In article <1991Jun26.232121.29755 at watmath.waterloo.edu> datangua at watmath.waterloo.edu (David Tanguay) writes:
   > [Essentially, assigning a (char **) value to a (const char **)
   > variable.]

   I don't believe it, either. In 3.3.16.1, Simple Assignment, Constraints:
	   both operands are pointers to qualified of unqualified
	   versions of compatible types, and the type pointed to by
	   the left has all the qualifications of the type pointed to
	   by the right

   Your code satisfies this constraint (the others don't pertain to
   the example).  If you remove one level of indirection, you have a
   very common situation, with the way the library routines are
   declared.  E.g., int printf( const char *, ... )

Strange as it may seem, that's not true.  If you assign A = (char *)
to B = (const char *), then A and B are pointers to qualified versions
of compatible types (char / const char).  However, in the case of A =
(char **) and B = (const char **), A is a pointer to (char *) and B is
a pointer to (const char *), which are *not* compatible. Remember,
(const char *) is not the const-qualified version of (char *), (char *
const) is.

Dale Worley		Compass, Inc.			worley at compass.com
--
It's getting so the only place you can find a Communist is in an
American university.



More information about the Comp.lang.c mailing list