Reputation: 49
Im having trouble with my project of the university when i compile my files they are 5 (api.c api.h datastruct.c datastruct.h and main.c) with MakeFile the problem is in the datastruct.c and datastruct.h when compiles this functions:
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);
}
and in the file datastruct.h i have the structure definition:
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;
i cant see the problem datastruct.h is included in datastruct.c!!! The error on compiler is:
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
Upvotes: 0
Views: 404
Reputation: 37945
Read carefully what you wrote:
vertex new_vertex = NULL; // Declare an element of type 'vertex'
But what is vertex
?
typedef struct vertex_t *vertex; // A pointer to a 'struct vertex_t'
So what is a struct vertex_t
? Well, it doesn't exist. You defined the following:
typedef struct _vertex_t {
...
} vertex_t;
That's two definitions:
struct _vertex_t
vertex_t
No such thing as struct vertex_t
(the reasoning is similar for edge
). Change your typedefs to either:
typedef vertex_t *vertex;
typedef edge_t *edge;
Or:
typedef struct _vertex_t *vertex;
typedef struct _edge_t *edge;
Unrelated to your problem and as said in the comments by user Zan Lynx, allocating with calloc
will zero all the members of your struct, therefore initializing them with NULL
is superflous.
Upvotes: 3
Reputation: 54325
I found it.
Your problem is in your typedef. In C typedef creates a new type name. Struct names however, are not type names.
So if you change typedef struct vertex_t *vertex
into typedef vertex_t *vertex
it will fix that error message.
Upvotes: 2
Reputation: 10655
Your problem is here:
typedef struct vertex_t *vertex;
typedef struct edge_t *alduin;
it should be:
typedef struct _vertex_t *vertex;
typedef struct _edge_t *alduin;
Upvotes: 2