Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!caip!think!nike!ucbcad!ucbvax!YALE.ARPA!FISCHER-MICHAEL From: FISCHER-MICHAEL@YALE.ARPA Newsgroups: net.micro.atari16 Subject: Re: bug in megamax C Message-ID: <8610141605.AA14752@ucbvax.Berkeley.EDU> Date: Tue, 14-Oct-86 12:06:09 EDT Article-I.D.: ucbvax.8610141605.AA14752 Posted: Tue Oct 14 12:06:09 1986 Date-Received: Fri, 17-Oct-86 20:11:35 EDT Sender: daemon@ucbvax.BERKELEY.EDU Reply-To: Organization: The ARPA Internet Lines: 37 From James M. Turner: here's a cute bug in megamax C: int c; while((c = getchar()) != EOF) { . . . } works fine but: unsigned char c; while((c = getchar()) != EOF) { . . . } loops infinately, the problem is that megamax generates the following code: AND #0xff,D0 ;D0 has the result of getchar CMP #-1,D0 ;ooppsss should be CMP.B As well it should! EOF is -1. An "unsigned" number is always positive and hence can never equal a negative number. The reason c must be an int and not a char is that getchar() might return any any of 256 valid bytes as well as the EOF indicator -- 257 values in all, and they won't fit into 8 bits. --Mike Fischer -------