Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!husc6!cmcl2!brl-adm!umd5!mimsy!chris From: chris@mimsy.UUCP (Chris Torek) Newsgroups: comp.lang.c Subject: Re: Comparing chars to constants Message-ID: <9101@mimsy.UUCP> Date: Mon, 26-Oct-87 01:48:14 EST Article-I.D.: mimsy.9101 Posted: Mon Oct 26 01:48:14 1987 Date-Received: Wed, 28-Oct-87 02:51:57 EST References: <4663@elroy.Jpl.Nasa.Gov> <2515@mmintl.UUCP> Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742 Lines: 32 In article <2515@mmintl.UUCP> franka@mmintl.UUCP (Frank Adams) writes: >... I will note that one other way to write this, with the new ANSI >standard, would be: > > if (p == 0x80u) > >This will coerce p to unsigned. . . . which means that if p is a signed character, it will extend from 0x80 == -128 to 0xff80 (assuming 16 bit int), and the comparison will still always be false. Incidentally, there is a bug in certain Sun compilers that causes char c = 0x80; if (c == (int)(char)0x80) ... to fail. Changing the code to if (c == (int)(char)(int)0x80) ... makes the test succeed. Curiously, char c = 0x80, d = 0x80; if (c == (int)(char)d) ... succeeds without the extra (int) cast. Chris -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7690) Domain: chris@mimsy.umd.edu Path: uunet!mimsy!chris