Genralizing Pointer Routines

Kevin Weller n025fc at tamuts.tamu.edu
Thu Dec 13 06:10:48 AEST 1990


In article <1990Dec12.002520.25210 at doe.utoronto.ca> david at doe.utoronto.ca (David Megginson) writes:

   One trick which I know is to define a generic structure or two to
   get at linked-list pointers. For example,

   struct list1 {
	   struct list1 * next;
   };

   struct list2 {
	   struct list2 * next;
	   struct list2 * prev;
   };

   Now, you can write functions to deal with any arbitrary linked list
   of structures, as long as the links are always the first element of
   the structures. ....


   David Megginson

That's the way I do it.  A whole subsection of my own C library is
devoted to this (when it's "done," I hope to release this library as
freeware, ISAM manager and all).

I was assigned to write two programs in Pascal class, both doing the
same thing, but one with an array and the other with a linked list.  I
wanted to write two sets of low-level procedures to handle the two
different data structure types, then just plug in the right set of
routines into one high-level program like I would do in C.  Hah!  I
had to introduce one kludge after another due to Pascal's data typing
rules until the low-level stuff was no longer very general.  C, by
comparison, has so many features supporting procedural abstraction
that Pascal lacks, and I guess I've been spoiled.


--
Kevin L. Weller                                 /-------+--------------------\
internet: n025fc at tamuts.tamu.edu                |  aTm  |  GIG 'EM, AGGIES!  |
CIS:      73327,1447                            \-------+--------------------/



More information about the Comp.lang.c mailing list