4.3.1 Representation

The internal representation of a list and a list node are as follows:

struct List // this should be in list.h
{
};

extern struct List *pList_emptylist; // in list.h
      
// provider-only definitions
struct _Listnode;

struct _List
{
  struct _Listnode *first;
};

struct _List _List_emptylist = { NULL };

struct List *pList_emptylist = (struct List *)&_List_emptylist;

struct _Listnode
{
  char firstvalue; // we can change this type
  struct _List rest; // where is the next one?
};

There is a difference between a struct _List and a struct _Listnode. The first represent an entire list, whereas the second represent a component of a list. The published type struct List is a mask of struct _List. This means that struct _Listnode has no exposure to consumer code.



Copyright © 2006-09-27 by Tak Auyeung