I would like to know how to solve the errors for redefinition of the typedef struct QueueADT.
error messages
gcc -std=c99 -ggdb -Wall -Wextra -c queueADT.c
queueADT.c:22:3: error: 'QueueADT' redeclared as different kind of symbol
}*QueueADT;
^
In file included from queueADT.c:9:0:
queueADT.h:23:21: note: previous declaration of 'QueueADT' was here
typedef struct { } *QueueADT;
^
queueADT.c:30:1: error: unknown type name 'QueueADT'
QueueADT que_create( int (*cmp)(const void*a,const void*b) ) {
^
queueADT.c:30:10: error: conflicting types for 'que_create'
QueueADT que_create( int (*cmp)(const void*a,const void*b) ) {
^
In file included from queueADT.c:9:0:
queueADT.h:44:10: note: previous declaration of 'que_create' was here
QueueADT que_create( int (*cmp)(const void*a,const void*b) );
^
The .h file has a definition if not compiling which is the queueADT and que_create
#ifndef _QUEUE_IMPL_
typedef struct { } *QueueADT;
#endif
QueueADT que_create( int (*cmp)(const void*a,const void*b) );
Now I am not sure how to define the QueueADT struct and the que_create from the .c file here
#ifndef _QUEUE_IMPL_
#include "queueADT.h"
struct node {
void* data;
//size_t num;
struct node *next;
}node;
typedef struct QueueADT {
struct node *front; /* pointer to front of queue */
struct node *rear; /* pointer to rear of queue */
int *contents[ QUEUE_SIZE ]; /* number of items in queue */
int *cmprFunc; /* The compare function used for insert */
}*QueueADT;
QueueADT que_create( int (*cmp)(const void*a,const void*b) ) {
struct QueueADT *new;
new = (struct QueueADT*)malloc(sizeof(struct QueueADT));
if (cmp == NULL) {
//do I create a new pointer to the cmp_int64?
new->front = NULL;
new->rear = NULL;
new->cmprFunc = NULL;
} else {
new->cmprFunc = &cmp;
new->front = NULL;
new->rear = NULL;
}
return ( new );
}
Edit 1 Error message went from
queueADT.c:22:3: error: 'QueueADT' redeclared as different kind of symbol
}*QueueADT;
^
In file included from queueADT.c:9:0:
queueADT.h:23:21: note: previous declaration of 'QueueADT' was here
typedef struct { } *QueueADT;
^
queueADT.c:30:1: error: unknown type name 'QueueADT'
QueueADT que_create( int (*cmp)(const void*a,const void*b) ) {
^
To
In file included from queueADT.c:8:0:
queueADT.h:44:1: error: unknown type name 'QueueADT'
QueueADT que_create( int (*cmp)(const void*a,const void*b) );
^
queueADT.h:49:19: error: unknown type name 'QueueADT'
void que_destroy( QueueADT queue );
#define QUEUE_SIZE 5
#include "queueADT.h"
#define _QUEUE_IMPL_
struct node {
void* data;
//size_t num;
struct node *next;
}node;
typedef struct QueueADT {
struct node *front; /* pointer to front of queue */
struct node *rear; /* pointer to rear of queue */
//int *contents[ QUEUE_SIZE ]; /* number of items in queue */
int *cmprFunc; /* The compare function used for insert */
}*QueueADT;
QueueADT que_create( int (*cmp)(const void*a,const void*b) ) {
struct QueueADT *new;
new = (struct QueueADT*)malloc(sizeof(struct QueueADT));
if (cmp == NULL) {
//do I create a new pointer to the cmp_int64?
new->front = NULL;
new->rear = NULL;
new->cmprFunc = NULL;
} else {
new->cmprFunc = &cmp;
new->front = NULL;
new->rear = NULL;
}
return ( new );
}
The reason it wasnt finding the queueStruct was not defined as a type for QueueStruct que_crear was because they weren't being defined in the order listed below
typedef struct node {
void* data;
struct node *next;
}node;
struct queueStruct {
struct node *front; /* pointer to front of queue */
struct node *rear; /* pointer to rear of queue */
int *cmprFunc;
size_t num; /* The compare function used for insert */
};
typedef struct queueStruct *QueueADT;
#define _QUEUE_IMPL_
#include "queueADT.h"
so @Drew I did need the single line header but it had to be defined after the struct queueStruct and before queueADT.h