🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: net.micro.mac
Article #6230

Re: Megamax bug?

#6230
From: John Bruner
Date: Wed, 25 Jun 1986 15:48
37 lines
2103 bytes
Regarding Megamax bugs, I've discovered that the (2.1b) compiler seems
to have trouble with type casts, particularly those in which a value
is cast to a narrower type.  For instance, one bug which really drove
me crazy recently was a piece of code approximately like this:

	struct win_info *w;
	typedef unsigned char row_t, col_t;

	tty_erasep(w, (row_t)0, (col_t)0);

The code it generated was (approximately):

	CLR.W	-(SP)
	CLR.W	-(SP)
	MOVE.L	A2,-(SP)
	JSR	tty_erasep
	ADDQ	#4,SP		<<- 4, not 8

Another problem I had with casts occurred when I was initializing a
data structure.  The first element of the structure was an unsigned int.
I initialized it to (unsigned)-1 [using a macro].  The compiler
generated the correct initialization code but didn't allocate enough
space in the data segment; hence, the structure overlapped variables
declared later.  This also was a real "joy" to find.

I don't seem to have as much difficulty with casts to wider types.
Since I redefine NULL to be 0 (instead of the incorrect 0L defined
in <stdio.h>) I don't run into this problem.

Also I discovered that pointers to functions cannot be compared
(except to NULL), because two pointers to the same function may not
have the same representation.  (I understand why this is so, but
it is annoying nonetheless.)
-- 
  John Bruner (S-1 Project, Lawrence Livermore National Laboratory)
  MILNET: jdb@mordor [jdb@s1-c.ARPA]	(415) 422-0758
  UUCP: ...!ucbvax!decwrl!mordor!jdb 	...!seismo!mordor!jdb
Technical Details
Message-ID: <9021@mordor.ARPA>
Path: arc1-ca.pugleaf.net!utzoo!watmath!clyde!burl!ulysses!allegra!princeton!caip!ut-sally!seismo!lll-crg!styx!mordor!jdb
References: <1023@k.cs.cmu.edu> <3700001@megamax> <2636@ism780c.UUCP>

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!burl!ulysses!allegra!princeton!caip!ut-sally!seismo!lll-crg!styx!mordor!jdb
From: jdb@mordor.ARPA (John Bruner)
Newsgroups: net.micro.mac
Subject: Re: Megamax bug?
Message-ID: <9021@mordor.ARPA>
Date: Wed, 25-Jun-86 11:48:18 EDT
Article-I.D.: mordor.9021
Posted: Wed Jun 25 11:48:18 1986
Date-Received: Sat, 28-Jun-86 07:04:33 EDT
References: <1023@k.cs.cmu.edu> <3700001@megamax> <2636@ism780c.UUCP>
Reply-To: jdb@mordor.UUCP (John Bruner)
Organization: S-1 Project, LLNL
Lines: 37