首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >“'struct <anonymous>”没有名为

“'struct <anonymous>”没有名为
EN

Stack Overflow用户
提问于 2014-10-30 20:28:15
回答 2查看 19.6K关注 0票数 4

寻找引用节点的方法,并将其设置为创建函数的null。来自给定输出的任何建议将队列中的前节点和后节点设置为NULL?

代码语言:javascript
复制
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;

以下是导致错误的代码的主要部分。(2个结构)

代码语言:javascript
复制
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 );
}
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2014-10-30 20:32:56

这在我看来是无效的:

代码语言:javascript
复制
    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;
        ...

也许你需要这个:

代码语言:javascript
复制
    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;
        ...

代码语言:javascript
复制
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 */
};

可能应该是

代码语言:javascript
复制
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 */
};

这里的typedef是没有意义的,应该删除它:

代码语言:javascript
复制
typedef struct node {
    void* data;
    //size_t num;
    struct node *next;
};

其他问题:struct QueueADT中的这两个声明在我看来很可疑:

代码语言:javascript
复制
    int *contents[ QUEUE_SIZE ];      /* number of items in queue  */
    int *cmprFunc;                    /* The compare function used for insert */
票数 3
EN

Stack Overflow用户

发布于 2014-10-30 20:31:39

删除从typedef struct node {..

  • Change typedef
  1. typedef struct QueueADT {//body}; be QueueADT *new;

以此类推..

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26652992

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档