Browse Prior Art Database

C-Language Generic Function Interface of any Data Structure Type Declaration

IP.com Disclosure Number: IPCOM000113555D
Original Publication Date: 1994-Sep-01
Included in the Prior Art Database: 2005-Mar-27
Document File: 4 page(s) / 116K

Publishing Venue

IBM

Related People

Geisler, RD: AUTHOR [+2]

Abstract

This disclosure describes an interface design method that accepts a linked list data structure of any type declaration. The interface provides the capability of determining how the data structure was declared by interpreting the information it receives. This interface allows an algorithm to be re-used on a variety of data structure types.

This text was extracted from an ASCII text file.
This is the abbreviated version, containing approximately 37% of the total text.

C-Language Generic Function Interface of any Data Structure Type
Declaration

      This disclosure describes an interface design method that
accepts a linked list data structure of any type declaration.  The
interface provides the capability of determining how the data
structure was declared by interpreting the information it receives.
This interface allows an algorithm to be re-used on a variety of data
structure types.

      This article describes a programming interface that takes
advantage of the common aspects of linked list data structures.  This
interface provides programmers with the ability to reuse algorithms
independently of the data structure type.  The following example
describes a single threaded linked list, but can be applied to other
types of linked lists as well.

      The interface allows the location of these pointers to be
calculated by passing the address of the first byte of the structure
along with the address of the next and/or previous pointers within
the structure.  The linked list can then be traversed by setting the
list pointer equal to the address of the first byte plus the offset
to the next pointer.  Any additional pointer can be generated using
the same method of adding its offset to the address of the first byte
of the structure.

      A C-language display algorithm is used to illustrate this
example, but can also be implemented for other types of algorithms.
Also included is a sample prototype and function call for a Sort
routine.

o  Data Structure Type Declaration  ("sample.h")
   struct examplerec
   { int   data1;                    /* Integer Data  */
    int   data2;                     /* Integer Data */
    struct examplerec *nextlistptr;  /* Pointer to next structure */
      }; /* end ("sample.h") */

o   Sample Display Program  ("sample.c")
     #include <malloc.h>
     #include <stdlib.h>
     #include <stdio.h>
     #include "sample.h"                  /* Local Include file */
     /* function prototypes       */
     int  display_function(void *);
     int  generic_traverse(void  *  , void ** , int (*)(void * ));
     int  generic_free(void  * , void **);

o   Start of Main
     void main()
     { struct examplerec *firstlistptr, *thislistptr,
                         *lastlistptr, *newlistptr;
       int  rec_cnt = 0;
       int  errcode = 0;
     firstlistptr = (struct examplerec *)NULL;  /* Set first list
    pointer */
     lastlistptr = (struct examplerec *)NULL;   /* Set last list
    pointer  */
     while (rec_cnt<10)                         /* Load list of
    records   */
       { newlistptr = (struct examplerec *) malloc( sizeof(struct
    examplerec));
         if (newlistptr == (struct examplerec *)NULL) /* check
    a...