我有以下代码部分:
字典.h
#ifndef _DICTIONARY_H
#define _DICTIONARY_H
typedef struct _dict_t dict_t;
typedef dict_t *Dictionary;
Dictionary dict_new(void);
(...)
字典.c
#include "dictionary.h"
struct _dict_t {
unsigned int size;
char **data;
};
Dictionary dict_new(void){
Dictionary dict = NULL;
dict = calloc(1, sizeof(struct _dict_t));
dict->data = calloc(1, sizeof(char));
dict->size = 0;
return (dict);
}
main.c
#include "dictionary.h"
Dictionary main_dict; // global dictionary
Dictionary ignored; // Yes, i know its horrible
int is_known(char *word){
int i;
for (i = 0; i < main_dict->size; ++i) {
if (strcmp(main_dict->data[i], word) == 0)
return 1;
}
for (i = 0; i < ignored->size; ++i){
if (strcmp(ignored->data[i], word) == 0)
return 1;
}
return 0;
}
int main(){
(...)
}
许多错误之一(取消引用指向不完整类型的指针)如下:
main_dict->size
我找不到错误。发生了什么事?
最佳答案
当类型不完整时,编译器不知道该类型的实例内部有什么。您需要先提供类型的定义,然后才能取消引用它。
关于c - 取消引用指向不完整类型抽象数据类型的指针,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29682306/