当我编译我的文件,他们是5(api.c api.h datastruct.c datastruct.h和main.c)与MakeFile的问题是在datastruct.c和datastruct我有我的大学项目的麻烦。 h当编译此功能:我的struct typedef导致“解除引用指向不完整类型的指针?”有什么问题?
vertex new_vertex() {
/*This functions allocate memorie for the new struct vertex wich save
the value of the vertex X from the edge, caller should free this memorie*/
vertex new_vertex = NULL;
new_vertex = calloc(1, sizeof(vertex_t));
new_vertex->back = NULL;
new_vertex->forw = NULL;
new_vertex->nextvert = NULL;
return(new_vertex);
}
,并在文件中datastruct.hi有结构定义:
typedef struct vertex_t *vertex;
typedef struct edge_t *alduin;
typedef struct _edge_t{
vertex vecino; //Puntero al vertice que forma el lado
u64 capacidad; //Capacidad del lado
u64 flujo; //Flujo del lado
alduin nextald; //Puntero al siguiente lado
}edge_t;
typedef struct _vertex_t{
u64 verx; //first vertex of the edge
alduin back; //Edges stored backwawrd
alduin forw; //Edges stored forward
vertex nextvert;
}vertex_t;
我看不到的问题datastruct.h包括在datastruct.c! 对编译器的错误是:
gcc -Wall -Werror -Wextra -std=c99 -c -o datastruct.o datastruct.c
datastruct.c: In function ‘new_vertex’:
datastruct.c:10:15: error: dereferencing pointer to incomplete type
datastruct.c:11:15: error: dereferencing pointer to incomplete type
datastruct.c:12:15: error: dereferencing pointer to incomplete type
什么问题?请显示错误消息什么编译器输出。 –
关于风格的评论:typedef'ing指针在我看来是一个很大的错误,因为在C中知道你正在处理的是非常重要的。我只是吮吸它并在我需要的地方输入'struct vertex_t *'。 –
你也可以使用'calloc'来分配内存,'calloc'将内存设置为0.所以你不需要所有这些NULL赋值。 –