Re: derefrencing pointer to incomplete type
- From: Michael Mair <Michael.Mair@xxxxxxxxxxxxxxx>
- Date: Sat, 30 Sep 2006 23:39:06 +0200
Note:
- This has also been posted to gnu.gcc.help, message
<1159642467.628856.89800@xxxxxxxxxxxxxxxxxxxxxxxxxxx>
Please indicate this fact in all groups you post to, so you do not
make people tell you the same things independently.
- Your code contains much vertical spacing; I threw it out without
explicit notes.
friend.05 wrote:
1)
#include <stdio.h>
#include <stdlib.h>
#include "graph.h"
#define MAX_VTX 4
struct _graph_vertex {
Leading underscores do not "belong" to the user in many cases.
It is a good idea not to use them if you are not sure in which
cases they belong to you and in which they do not.
<snip>
//g.adjmtx[i][j]=(struct _graph_edge*)malloc(sizeof(struct
_graph_edge));
As illustrated by the above: // comments are bad for posting
code in usenet.
g.adjmtx[i][j]=(graph_edge_pointer)malloc(sizeof(graph_edge));
- This statement is outside of a loop.
- It is unnecessary to cast the return value of malloc(); this
can hide an error. If your compiler complains if you take away
the cast _and_ have included <stdlib.h> then you are compiling
C code with a C++ compiler (or in the compiler's C++ mode) --
bad idea.
- the favoured form of allocation around here is
T *p;
...
p = malloc(sizeof *p);
If the type of p changes, then nothing goes wrong.
- you forgot to check for malloc() success or failure.
<snip>
2)
#include <stdio.h>
#include <stdlib.h>
#include "graph.h"
int main()
{
int src_vtx[]= {0,1,3,0,3};
int snk_vtx[] = {1,2,2,3,1};
int edgcnt = sizeof(src_vtx)/sizeof(int);
graph_pointer gp;
gp = graph_construct(src_vtx,snk_vtx,edgcnt);
printf("%d",gp->vertices[1].exectime);
I am getting error over here:
gcc : derefrencing pointer to incomplete type
You did not give the structure definition in "graph.h" but
only said "I mean 'struct _graph *' whenever I say 'graph_pointer'".
The compiler only knows that there is a type "struct _graph" but
not what it looks like.
Either do not try to access the interna of your graphs from outside
the graph "library" or move the struct definitions to "graph.h".
vc++ : left of 'vertices' specifies undefined struct/union '_graph'
return 0;
You do not post your full programme -- this code will not compile.
3) graph.h
#ifndef _graph_h
#define _graph_h
#include "floatmath.h"
As you did not provide floatmath.h (or at least neglected to point
out which of "1)" and "2)" is supposed to be that), I cannot
compile your code -- you make it unnecessarily hard to help you.
/* A vertex in a graph. */
typedef struct _graph_vertex graph_vertex;
/* A pointer to a graph vertex. */
typedef graph_vertex *graph_vertex_pointer;
/* An edge in a graph. */
typedef struct _graph_edge graph_edge;
/* A pointer to a graph edge. */
typedef graph_edge *graph_edge_pointer;
/* A graph. */
typedef struct _graph graph_type;
/* A pointer to a graph. */
typedef graph_type *graph_pointer;
/* An array of pointers to graph edges. */
typedef graph_edge_pointer *graph_edge_array;
graph_pointer graph_construct(int *, int *, int);
#endif
Cheers
Michael
--
E-Mail: Mine is an /at/ gmx /dot/ de address.
.
- Follow-Ups:
- Re: derefrencing pointer to incomplete type
- From: friend.05
- Re: derefrencing pointer to incomplete type
- References:
- derefrencing pointer to incomplete type
- From: friend.05
- derefrencing pointer to incomplete type
- Prev by Date: Re: rolling dice
- Next by Date: Re: derefrencing pointer to incomplete type
- Previous by thread: derefrencing pointer to incomplete type
- Next by thread: Re: derefrencing pointer to incomplete type
- Index(es):
Relevant Pages
|
|