當我編譯我的文件,他們是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賦值。 –