Reputation: 21
So, I'm trying to write a few tests. I have a file called listQueue.c (not shown but working) which contains a series of a bunch of function operations on 'queues'. Now my problem lies when I try to write some tests for one of the functions in listQueue.c in a separate file I called testQueue.c.
My listQueue.c:
// Creates an empty Queue
Queue createQueue (void){
Queue q = malloc (sizeof (*q));
assert(q != NULL);
q->head = NULL;
q->tail = NULL;
q->size = 0;
return q;
}
testQueue.c contains:
int main (int argc, char *argv[]){
printf("Test 1 - Testing create q\n");
Queue q = createQueue();
printf("%d", q->size);
assert(q->head == NULL);
assert(q->tail == NULL);
printf("All tests passed, createQueue works fine.\n");
return 0;
}
The 'header file' Queue.h "
typedef struct queueImp *Queue;
//Function Prototypes
Queue createQueue(void);
Now when I tried to compile it it spits out an error.
"Dereference pointer to an incomplete type." I suspect it's something to do with how I called createQueue. Any help would be appreciated. Thanks. And yes I have included Queue.h above my main!
Upvotes: 1
Views: 221
Reputation: 121407
When you deference q
in main(), compiler hasn't seen the definition of struct queueImp
yet. Hence, it errors out as the compiler can't determine the size of the object.
Put the defintion of struct queueImp
(not sure where you have it at the moment -- I don't see anywhere in your posted code) in queue.h
and make sure to include it.
Upvotes: 4