negative addresses
Alan J Rosenthal
flaps at dgp.toronto.edu
Sun May 22 13:32:08 AEST 1988
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.
More information about the Comp.lang.c
mailing list