繁体   English   中英

取消引用不完整类型的指针[在结构上工作]

[英]Dereferencing pointer to incomplete type [Working on structs]

我已经声明:

#include stdio.h

#include stdlib.h

#include string.h

#include dictionary.h

int main( int argc, char ** argv ){

    char * dictionary_name = DEFAULT_DICTIONARY;
    dictionary_t dictionary;
    dictionary->entries = 1;
    if ( dictionary == NULL){
        printf("NULL\n");
        return -1;
    }
    return 0;
}

错误:

src/main.c: In function ‘main’:
src/main.c:40:12: error: dereferencing pointer to incomplete type ‘struct dictionary_s’
dictionary->entries = 1;

在dictionary.c中:

#include dictionary.h

struct dictionary_s{

    char * name;
    llist_t content;
    int entries;
};

在标头(dictionary.h)中:

typedef struct dictionary_s* dictionary_t;

这是我第一次在这里问一个问题,所以,如果我错过了重要的事情,请原谅我。

文件dictionary.h仅包含类型struct dictionary_s的名称,因此对main函数可见。 这意味着它不知道结构包含什么。

您需要将struct dictionary_s的定义移动到头文件中。 这样就可以从main使用它。

您必须将struct的定义放在头文件中,而不是在dictionary.c -file中; 否则,其成分在dictionary.c之外是未知的。

因此,您的dictionary.h应该如下所示:

struct dictionary_s{

    char * name;
    llist_t content;
    int entries;
};

typedef struct dictionary_s* dictionary_t;

您的文件dictionary.c可能已过时。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM