我有以下代码部分:
dictionary.h
#ifndef _DICTIONARY_H
#define _DICTIONARY_H
typedef struct _dict_t dict_t;
typedef dict_t *Dictionary;
Dictionary dict_new(void);
(...)
dictionary.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
我找不到错误。发生了什么事?
答案 0 :(得分:0)
当类型不完整时,编译器不知道该类型的实例内部是什么。在取消引用之前,您需要提供类型的定义。