🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: net.micro.atari16
Article #2386

Re: bug in megamax C

#2386
From: FISCHER-MICHAEL
Date: Tue, 14 Oct 1986 16:06
37 lines
1398 bytes
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 <fischer@yale.arpa>

-------
Technical Details
Message-ID: <8610141605.AA14752@ucbvax.Berkeley.EDU>
Path: arc1-ca.pugleaf.net!utzoo!watmath!clyde!caip!think!nike!ucbcad!ucbvax!YALE.ARPA!FISCHER-MICHAEL

Show Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: arc1-ca.pugleaf.net!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: <FISCHER-MICHAEL@YALE.ARPA>
Organization: The ARPA Internet
Lines: 37