Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!husc6!rutgers!topaz.rutgers.edu!ron From: ron@topaz.rutgers.edu (Ron Natalie) Newsgroups: comp.lang.c Subject: Re: Comparing chars to constants Message-ID: <15706@topaz.rutgers.edu> Date: Mon, 19-Oct-87 15:34:27 EDT Article-I.D.: topaz.15706 Posted: Mon Oct 19 15:34:27 1987 Date-Received: Tue, 20-Oct-87 06:50:04 EDT References: <4663@elroy.Jpl.Nasa.Gov> Organization: Rutgers Univ., New Brunswick, N.J. Lines: 13 Correct. The character comparison "c == 0x80" is non portable since chars may or may not be unsigned innately. On machines where char's are signed, 0x80 would likely become -0x80 (e.g. on 32 bit ints, 0xFFFFFF80) when converted to int (usual arithmatic conversions). The compiler in question is being smart in noting that no conversion of a char to an int has values outside the range -0x80 to +0x7F. Using the (char) cast on the constant causes the conversion of char to int to occur on the constant yielding the sign extension. This doesn't happen otherwise because 0x80 is already of type integer so no conversion is called for. -Ron