type of character constants

Henry Spencer henry at utzoo.uucp
Sun Mar 19 08:17:54 AEST 1989


In article <1813 at dlvax2.datlog.co.uk> scm at datlog.co.uk ( Steve Mawer ) writes:
>So what is the 'correct' value for '\377', 255 or -1?

Precisely! :-)  The correct value is "255 or -1".  If char is signed in
the particular implementation, the value is -1 (assuming 8-bit chars);
if char is unsigned, the value is 255.  The X3J11 rule is essentially
that 'x' == (int)(char)'x' for all x, so it depends on whether conversion
of char to int sign-extends.  Code that depends on one particular choice
is non-portable.
-- 
Welcome to Mars!  Your         |     Henry Spencer at U of Toronto Zoology
passport and visa, comrade?    | uunet!attcan!utzoo!henry henry at zoo.toronto.edu



More information about the Comp.lang.c mailing list