Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!rutgers!husc6!necntc!cullvax!drw From: drw@cullvax.UUCP Newsgroups: comp.lang.c Subject: Character types in ANSI C Message-ID: <816@cullvax.UUCP> Date: Thu, 19-Feb-87 11:29:08 EST Article-I.D.: cullvax.816 Posted: Thu Feb 19 11:29:08 1987 Date-Received: Fri, 20-Feb-87 21:39:26 EST Organization: Cullinet Software, Inc., Westwood, MA Lines: 31 cg@myrias.UUCP (Chris Gray) writes: > I.e. which of the following are legal: > > char *p1; > unsigned char *p2; > signed char *p3; > > p1 = p2; /* case 1 */ > p1 = p3; /* case 2 */ > p2 = p3; /* case 3 */ Well, the char's are all widened into the 'appropriate' int types. (These are called integral promotions, or some such.) Then the appropriate comparisons of int's and/or unsigned int's are performed. I think that the rule for widening char's to int's is "a character type is promoted to unsigned int if all possible values of the character type can be represented by unsigned int, otherwise it is promoted to int". Thus, you get: p2 = p2 <-> (unsigned int)p2 = (unsigned int)p2 p3 = p3 <-> (int)p3 = (int)p3 p2 = p3 <-> (unsigned int)p2 = (unsigned int)(int)p3 (p1 acts like p2 or p3, depending on whether chars are signed) Dale -- Dale Worley Cullinet Software UUCP: ...!seismo!harvard!mit-eddie!cullvax!drw ARPA: cullvax!drw@eddie.mit.edu