[comp.std.c] incompatibility of character pointers

blodgett@granite.cr.bull.com (Bruce Blodgett) (02/07/90)

As far as I can tell, the following code fragment is not legal ANSI C:
{
  char * cp;
  unsigned char * ucp;
  signed char * scp;

  cp = "abc"; /* ok - string literal (array of char) becomes pointer to char */
  ucp = "def"; /* pointer to unsigned char INCOMPATIBLE with pointer to char */
  scp = "ghi"; /* pointer to   signed char INCOMPATIBLE with pointer to char */
}
Constraint from simple assignment section 3.3.16.1:
"One of the following shall hold:
... both operands are pointers to ... compatible types"

Now consider the types being pointed to (unsigned char vs char vs signed char).

From compatible type section 3.1.2.6:
"Two types have compatible type if their types are the same.  Additional rules
for determining whether two types are compatible are described in section
3.5.2 for type specifiers"

From type specifier section 3.5.2:
"Each list of type specifiers shall be one of the following sets"
Since char, signed char, and unsigned char form three distinct lists, they
are not the same type.  Consequently, pointers to them are NOT compatible
types.  Am I wrong?

Bruce Blodgett

karl@haddock.ima.isc.com (Karl Heuer) (02/08/90)

In article <1990Feb6.163933.11022@granite.cr.bull.com> blodgett@granite.cr.bull.com (Bruce Blodgett) writes:
>As far as I can tell, the following code fragment is not legal ANSI C:
>[Mixing any of "char *", "unsigned char *", or "signed char *" without casts]
>[Quotes from ANS indicate that they are not compatible types]

Sounds right to me.  What's the problem?

Karl W. Z. Heuer (karl@ima.ima.isc.com or harvard!ima!karl), The Walking Lint