Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!husc6!rutgers!bellcore!faline!ulysses!allegra!alice!ark From: ark@alice.UUCP Newsgroups: comp.lang.c Subject: Re: Comparing chars to constants Message-ID: <7373@alice.UUCP> Date: Sun, 18-Oct-87 15:34:06 EDT Article-I.D.: alice.7373 Posted: Sun Oct 18 15:34:06 1987 Date-Received: Mon, 19-Oct-87 01:59:37 EDT References: <4663@elroy.Jpl.Nasa.Gov> Organization: AT&T Bell Laboratories, Liberty Corner NJ Lines: 21 In article <4663@elroy.Jpl.Nasa.Gov>, david@elroy.UUCP writes: > From 6.6 both sides are converted into ints, 0x80 stays the > same but if p is equal to 0x80 it may always be sign extended on > some machines depending on its character sign convientions. (the original question had to do with the expression c==0x80 where c is a character variable) Chars are indeed extended to ints for comparison, and that extension may or may not involve sign extension. Saying c == (char) 0x80 may indeed be more portable, as one would hope 0x80 will be converted to a char and then undergo the same sign exension as c, but I wouldn't want to bet on the compiler getting it right. Instead, consider making c an unsigned char or casting it: ((unsigned char) c) == 0x80 (the outer parentheses are there for clarity)