Genralizing Pointer Routines

Doug Gwyn gwyn at smoke.brl.mil
Wed Dec 12 07:34:04 AEST 1990


In article <cbN7yBm00UhW45Cnh2 at andrew.cmu.edu> rg2c+ at andrew.cmu.edu (Robert Nelson Gasch) writes:
>In PASCAL, if you have 3 linked lists of different pointer types,
>you have to write 3 different Insert, search & delete routines; one
>for each pointer type. I was wondering if these routines can be 
>generalized for any pointer type in C?

Yes, the simplest scheme is to have a special "linkage" substructure
as the first member of each type of node structure.  By appropriate
use of casts etc., common link-manipulation routines can be used for
all the node types, in a portable ("strictly conforming") manner.

Tom Plum's "Reliable Data Structures in C" contains examples.  You
might also contact Karen Murray <Karen at BRL.MIL> about obtaining the
MUVES "Dq" package source code, which is a fairly elaborate
implementation of the idea (complete with "lint" escapes).



More information about the Comp.lang.c mailing list