negative addresses

Eric Black ericb at athertn.Atherton.COM
Thu Jun 2 03:50:27 AEST 1988


1 Jun 88 17:50:27 GMT
Reply-To: ericb at mango.UUCP (Eric Black)
Organization: Atherton Technology, Sunnyvale, CA
Lines: 58
Xref: dciem comp.arch:4525 comp.lang.c:9205

In article <8805220452.AA14606 at explorer.dgp.toronto.edu> flaps at dgp.toronto.edu (Alan J Rosenthal) writes:
>
>Henry Spencer wrote:
>>>Unfortunately, it is a real problem, because there are zillions of
>>>programs that implicitly assume that pointers are all-zeros.
>
>Doug Gwyn replied:
>>I don't think this is true.  How about an example?
>
>Later, he wrote that he was still waiting for an example, so I'll provide one.
> [...description of linked list of nodes pointing to other nodes...]
>people forgot to bother to initialise the head.  When one was declared
>as auto, people called zero((char *)&thing,sizeof(struct dll_head)),
>zero() being a function which sets a region of memory to zero bits.
>
>So there's your example.

A wonderful example of non-portable code!  Essentially what you are doing
without making it explicit is punning the pointer, just as if you had
something like:
	union {
		long	ima_number;
		char	*ima_pointer;
	};
and set the bits via one union member, and looked at them via the other.

There are also "zillions of programs" that assume the order of characters
in a long, and break when moved from a VAX to a 68K, or other analogous move.

Such code should be punishable by forcing the programmer to port C programs
running under UNIX to run under PRIMOS.  (no :-)

>
>[We have since added an initialisation function!]
>
>ajr

Huzzah!  What happens now when people "forget to bother to initialise the
head"??  Buggy code is an existence proof for buggy code...  A non-portable
"safety net" for programmers of said buggy code doesn't seem to me to be
a whole lot different than device drivers that assume that all device
control and status registers look exactly like the CSR on Unibus devices;
both might be perfectly valid in the environment they assume, but are
quite wrong when taken out of that environment.

Note that such assumptions are not just machine-dependent; they can also
be compiler-dependent!

I hope there was a :-) truncated by NNTP in your article...

:-):-):-):-):-):-):-):-):-):-):-):-):-):-):-):-):-):-):-):-):-):-):-):-):-)


-- 
Eric Black	"Garbage in, Gospel out"
Atherton Technology, 1333 Bordeaux Dr., Sunnyvale, CA, 94089
   UUCP:	{sun,decwrl,hpda,pyramid}!athertn!ericb
   Domainist:	ericb at Atherton.COM



More information about the Comp.lang.c mailing list