Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!lll-crg!nike!ucbcad!ucbvax!cartan!brahms!ballou From: ballou@brahms (Kenneth R. Ballou) Newsgroups: net.lang.c Subject: Re: Mavin question -- Char data Message-ID: <168@cartanBerkeley.EDU> Date: Sat, 1-Nov-86 18:51:07 EST Article-I.D.: cartanBe.168 Posted: Sat Nov 1 18:51:07 1986 Date-Received: Mon, 3-Nov-86 21:57:35 EST References: <4142@ism780c.UUCP> Sender: daemon@cartanBerkeley.EDU Reply-To: ballou@brahms (Kenneth R. Ballou) Distribution: net Organization: Math Dept. UC Berkeley Lines: 30 In article <4142@ism780c.UUCP> marv@ism780c.UUCP (Marv Rubinstein) writes: > unsigned char uc; > char c; > > uc > -1 /* evaluates to 0 (for all uc) because -1 is converted to > unsigned */ > > c > -1 /* evaluates to 1 (for all c) because c is converted to > an *integer* whose range is 0..255 and the comparison is > a signed compare */ > >Now the question, is this C? Yes, it is correct. The results are a consequence of the rule that after automatic widening of types has occurred, if either operand is unsigned, then the expression is evaluated with unsigned operands. When I was first learning C, I made the very silly mistake of writing char ch; while ((ch = getchar) != EOF) which would work on some compilers and not on others. Naturally, the diffi- culty was that in some cases 'char' by default was unsigned, and so the comparison was done using unsigned arithmetic. --- Kenneth R. Ballou ...!ucbvax!cartan!brahms!ballou Dept. of Mathematics University of California Berkeley, California 94720