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: <821@cullvax.UUCP> Date: Fri, 20-Feb-87 11:26:38 EST Article-I.D.: cullvax.821 Posted: Fri Feb 20 11:26:38 1987 Date-Received: Sat, 21-Feb-87 06:33:35 EST Organization: Cullinet Software, Inc., Westwood, MA Lines: 28 drw@cullvax.UUCP (Dale Worley) writes: > 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". Wrong! The rule is "char is promoted to int if all possible values of the char type can be represented by int, otherwise it's unsigned int". (Personally I can't imagine when a (signed or unsigned) char couldn't be represented as 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) Wrong! All of these get casted directly to int and compared. Dale -- Dale Worley Cullinet Software UUCP: ...!seismo!harvard!mit-eddie!cullvax!drw ARPA: cullvax!drw@eddie.mit.edu