Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!husc6!bloom-beacon!oberon!cit-vax!elroy!david From: david@elroy.Jpl.Nasa.Gov (David Robinson) Newsgroups: comp.lang.c Subject: Comparing chars to constants Message-ID: <4663@elroy.Jpl.Nasa.Gov> Date: Sun, 18-Oct-87 02:09:10 EDT Article-I.D.: elroy.4663 Posted: Sun Oct 18 02:09:10 1987 Date-Received: Sun, 18-Oct-87 23:49:48 EDT Organization: Image Analysis Systems Grp, JPL Lines: 31 I have run into a difference between the SunOS 3.4 C compiler and the Masscomp C compiler for the following segment of code: foo(p) char p; { if (p == 0x80) return (1); return (0); } On a Sun, it generates the code that is commonly expected, but on a Masscomp is gives a warning "Comparison always false" and optimizes away the if statement. In reading K&R I was unsure of what is to happen, under 7.6 and 7.7 it claims that the "usual arithmetic conversions are performed". 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. Does this imply that the above comparision is truly non-portable? Both machines give the same result if it is rewritten as: if (p == (char)0x80) -- David Robinson elroy!david@csvax.caltech.edu ARPA david@elroy.jpl.nasa.gov (new) seismo!cit-vax!elroy!david UUCP Disclaimer: No one listens to me anyway!