Xref: utzoo comp.arch:5077 comp.lang.c:10595 Path: utzoo!dciem!nrcaer!scs!spl1!laidbak!att!pacbell!ames!pasteur!ucbvax!hplabs!hpda!athertn!ericb From: ericb@athertn.Atherton.COM (Eric Black) Newsgroups: comp.arch,comp.lang.c Subject: Re: negative addresses Message-ID: <186@mango.athertn.Atherton.COM> Date: 1 Jun 88 17:50:27 GMT Article-I.D.: mango.186 References: <2393@uvacs.CS.VIRGINIA.EDU> <21541@amdcad.AMD.COM> <1988May12.162906.16901@utzoo.uucp> <7881@brl-smoke.ARPA> <8805220452.AA146 1 Jun 88 17:50:27 GMT Reply-To: ericb@mango.UUCP (Eric Black) Organization: Atherton Technology, Sunnyvale, CA Lines: 58 Xref: dciem comp.arch:4525 comp.lang.c:9205 In article <8805220452.AA14606@explorer.dgp.toronto.edu> flaps@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@Atherton.COM