In the below code,
/**********linkedListImpl.c ***********/
#include"list/list.h"
#if defined(LINKED_LIST)
/***************** Representation - start ******************/
/* struct members are not visible to other .c files */
static struct DListNode{
void *item;
struct DListNode *next;
struct DListNode *prev;
};
/* Should be used in this .c file, only, so static */
static typedef struct DListNode DListNode;
static DListNode* createNode(void *);
static struct List{
DListNode *head;
int size; /*size attribute is not part of list definition, but quick way
to help user code */
}List;
.....
#endif
/************ list.h ************/
#ifndef LIST_H /* Header guard */
#define LIST_H
#include"type.h"
/***************** Usage-start ************/
#if defined(ARRAY) || (LINKED_LIST)
typedef struct List List;
#else
#error "Wrong list implementation macro name !!!"
#endif
...
#endif /* LIST_H */
List type is declared in list.h, using staticspecifier,
typedef struct List List;
and defined in linkedListImpl.c, using staticspecifier,
static struct List{
DListNode *head;
int size;
}List;
Purpose: To make List symbol available to user(main.c) only through a pointer(List*). User(main.c) should not be able to access List members in main.c.
In linkedListImpl.c Symbol DListNode is defined using static specifier,
static struct DListNode{
void *item;
struct DListNode *next;
struct DListNode *prev;
};
static typedef struct DListNode DListNode;
Purpose: For symbol DListNode, user(main.c) should neither be able to access DListNode members in main.c nor access DListNode object through DListNode* pointer.
Is this the right approach to hide the symbols List & DListNode?
Note: Here is the complete code