Xref: utzoo comp.arch:4923 comp.lang.c:10262 Newsgroups: comp.arch,comp.lang.c Path: utzoo!utgpu!jarvis.csri.toronto.edu!dgp.toronto.edu!flaps From: flaps@dgp.toronto.edu (Alan J Rosenthal) Subject: Re: negative addresses Message-ID: <8805220452.AA14606@explorer.dgp.toronto.edu> Organization: University of Toronto References: <2393@uvacs.CS.VIRGINIA.EDU> <21541@amdcad.AMD.COM> <1988May12.162906.16901@utzoo.uucp> <7881@brl-smoke.ARPA> Date: Sat, 21 May 88 23:32:08 EDT 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. A large project on which I am currently working has many segments in which lists of things are manipulated; to a large extent mostly for displaying in menus, but also for other standard data processing kinds of tasks. There is a standardised doubly-linked list representation, and corresponding routines. The caller of these routines has as its representation of the list a "head" which contains header-like information for the list. When I first tried to use these routines, I looked through and found out how to do various operations. The operation I could not find was how to initialise a doubly-linked list after having declared the head. It turned out that a correct initialisation was to set the three pointers in a struct dll_head all to NULL. Since existing code usually happened to declare the head as either global or file static most 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. [We have since added an initialisation function!] ajr -- - Any questions? - Well, I thought I had some questions, but they turned out to be a trigraph.