A
Allan M. Bruce
I have a small implementation of a queue which I am trying to get to compile
but cant figure out why it doesnt work. I have copied the minimum
compilable code below. On gcc I get
temp2.c: In function `pop':
temp2.c:24: warning: initialization from incompatible pointer type
temp2.c:25: warning: assignment from incompatible pointer type
temp2.c: In function `destroy':
temp2.c:38: error: dereferencing pointer to incomplete type
In line 24, I am trying to intialise e which is an (entry *) to *xiQueue
which is a *(entry **) which should be an (entry *), no?
In line 38, I am dereferencing xiQueue which should give me an (entry *) so
I can access the members of the struct with ->, no?
In Visual C I get even more errors:
queue.c(24): error C2275: 'entry' : illegal use of this type as an
expression
queue.c(24): error C2065: 'e' : undeclared identifier
queue.c(25): error C2223: left of '->nextNode' must point to struct/union
queue.c(26): error C2223: left of '->data' must point to struct/union
queue.c(27): warning C4022: 'free' : pointer mismatch for actual parameter 1
queue.c(38): error C2037: left of 'nextNode' specifies undefined
struct/union 'entry'
Perhaps I am misunderstanding how to use typedef to make the queue
effectively an entry *. Can anybody help?
Thanks
Allan
#include <stdio.h>
#include <stdlib.h>
/*****************************************/
enum ERROR_CODES {ERROR, SUCCESS};
typedef struct entry *queue;
int pop(queue *, int *);
void destroy(queue *);
/*****************************************/
typedef struct tagEntry
{
int data;
struct tagEntry *nextNode;
} entry;
int pop(queue *xiQueue, int *xoData)
{
if (xiQueue == NULL)
return ERROR;
entry *e = *xiQueue;
*xiQueue = e->nextNode;
*xoData = e->data;
free(e);
return SUCCESS;
}
void destroy(queue *xiQueue)
{
if (xiQueue == NULL)
return;
int lDummy;
while ((*xiQueue)->nextNode != NULL)
pop(xiQueue, &lDummy);
xiQueue = NULL;
}
int main(void)
{
return 0;
}
but cant figure out why it doesnt work. I have copied the minimum
compilable code below. On gcc I get
temp2.c: In function `pop':
temp2.c:24: warning: initialization from incompatible pointer type
temp2.c:25: warning: assignment from incompatible pointer type
temp2.c: In function `destroy':
temp2.c:38: error: dereferencing pointer to incomplete type
In line 24, I am trying to intialise e which is an (entry *) to *xiQueue
which is a *(entry **) which should be an (entry *), no?
In line 38, I am dereferencing xiQueue which should give me an (entry *) so
I can access the members of the struct with ->, no?
In Visual C I get even more errors:
queue.c(24): error C2275: 'entry' : illegal use of this type as an
expression
queue.c(24): error C2065: 'e' : undeclared identifier
queue.c(25): error C2223: left of '->nextNode' must point to struct/union
queue.c(26): error C2223: left of '->data' must point to struct/union
queue.c(27): warning C4022: 'free' : pointer mismatch for actual parameter 1
queue.c(38): error C2037: left of 'nextNode' specifies undefined
struct/union 'entry'
Perhaps I am misunderstanding how to use typedef to make the queue
effectively an entry *. Can anybody help?
Thanks
Allan
#include <stdio.h>
#include <stdlib.h>
/*****************************************/
enum ERROR_CODES {ERROR, SUCCESS};
typedef struct entry *queue;
int pop(queue *, int *);
void destroy(queue *);
/*****************************************/
typedef struct tagEntry
{
int data;
struct tagEntry *nextNode;
} entry;
int pop(queue *xiQueue, int *xoData)
{
if (xiQueue == NULL)
return ERROR;
entry *e = *xiQueue;
*xiQueue = e->nextNode;
*xoData = e->data;
free(e);
return SUCCESS;
}
void destroy(queue *xiQueue)
{
if (xiQueue == NULL)
return;
int lDummy;
while ((*xiQueue)->nextNode != NULL)
pop(xiQueue, &lDummy);
xiQueue = NULL;
}
int main(void)
{
return 0;
}