I have a the following in a header file.
Code:
struct SortedList
{
void * data;
struct SortedList * next;
struct SortedList * previous;
int (*compareFunc)(void *, void *);
void (*destructor)(void *);
};
typedef struct SortedList* SortedListPtr;
SortedListPtr SLCreate(CompareFuncT cf, DestructFuncT df);
-------------------------------------------------------------------
In a .c file, I implemented the SLCreate function.
Code:
SortedListPtr SLCreate(CompareFuncT cf, DestructFuncT df)
{
struct SortedList item;
item.data = NULL;
item.next = (struct SortedList *) malloc(sizeof(struct SortedList));
item.previous = (struct SortedList *) malloc(sizeof(struct SortedList));
item.compareFunc = cf;
item.destructor = df;
SortedListPtr ptr = (struct SortedList *) malloc(sizeof(struct SortedList));
ptr = &item;
return ptr;
};
In main.c, I try to do the following:
Code:
SortedListPtr list = SLCreate(&compareInts, &destroy);
...... A bunch other code that does not alter list or it's contents at all.
struct SortedList item = (*list);
void * data = item.data;
if (data != NULL)
{
printf("Why did data become not null???\n");
}
-------------------------------------------------------------------
So my problem is how come my variable data became not null anymore when I haven't altered it at all and how can I fix this??