Character types in ANSI C
drw at cullvax.UUCP
drw at cullvax.UUCP
Sat Feb 21 02:26:38 AEST 1987
drw at 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 at eddie.mit.edu
More information about the Comp.lang.c
mailing list