'struct <anonymous>' has no name

Looking for a way to reference node and set it to null for the create function. Any suggestions from this result to enqueue the front and back nodes to NULL?

gcc -std=c99 -ggdb -Wall -Wextra  -c queueADT.c
queueADT.c:13:1: warning: useless storage class specifier in empty declaration [enabled by default]
 };
 ^
queueADT.c: In function 'que_create':
queueADT.c:36:6: error: 'struct <anonymous>' has no member named 'front'
   new->front = NULL;
      ^
queueADT.c:37:6: error: 'struct <anonymous>' has no member named 'rear'
   new->rear = NULL;
      ^
queueADT.c:38:8: error: expected identifier before '*' token
   new->*cmprFunc = NULL;

      

Here is the main part of the code that caused the errors. (2 structures)

typedef struct node {
    void* data;
    //size_t num;
    struct node *next;
};


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 */
};


#include "queueADT.h"


/// create a queue that is either sorted by cmp or FIFO
//function with two void
QueueADT que_create( int (*cmp)(const void*a,const void*b) ) {

    QueueADT new;
    new = (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 );
}

      

+3


source to share


2 answers


This looks invalid to me:

    struct QueueADT new;
    new = (QueueADT)malloc(sizeof(struct QueueADT));

    if (cmp == NULL) {
        //do I create a new pointer to the cmp_int64?
        new->front = NULL;
        ...

      

Perhaps you need this:

    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;
        ...

      

AND

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 */
};

      



it should be

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 */
};

      

And typedef

here it is pointless, you need to remove it:

typedef struct node {
    void* data;
    //size_t num;
    struct node *next;
};

      

Another problem: these two ads struct QueueADT

look suspicious to me:

    int *contents[ QUEUE_SIZE ];      /* number of items in queue  */
    int *cmprFunc;                    /* The compare function used for insert */

      

+2


source


  • Remove typedef

    fromtypedef struct node {..

  • Change struct QueueADT {//body};

    totypedef struct {//body}QueueADT;

  • QueueADT new;

    shoule be QueueADT *new;

    etc.



0


source







All Articles