Re: derefrencing pointer to incomplete type



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.
.



Relevant Pages

  • Re: derefrencing pointer to incomplete type
    ... /* Given an array of floating point numbers and the length of the ... struct _graph_vertex { ... If your compiler complains if you take away ... typedef struct _graph graph_type; ...
    (comp.lang.c)
  • Re: Naming typedefs
    ... problem that a scalar could be returned in the A register ... to have waste precious cpu cycles copying the struct there ... of the hardware or twentieth century compiler technology. ... # to include the header defining it into every other header (assuming ...
    (comp.unix.programmer)
  • Re: assembly language and reverse engineering
    ... "return arguments to struct pointed to by register" and ... assumptions of CDECL-like conventions (also supports STDCALL, ... arg for handling struct return (slightly compiler, and compiler version, ...
    (alt.lang.asm)
  • Re: C++ in ternms of C
    ... >about class and struct difference. ... How is the private and public part ... I tried to analise the ASM file produ ced my the VC++ compil er. ... >epresented by the c++ compiler in translation to intermediate stage. ...
    (microsoft.public.vc.language)
  • Re: List<> of struct with property. Cannot change value of property. why?
    ... method changes the struct that owns it. ... how would the compiler know the method changes the struct? ... Should the linker be required to carry this flag around too, so that when you import a reference to a struct type not compiled with the current project, you still have that information? ... There's a time and place for a value type, and in fact they even have their place in lists. ...
    (microsoft.public.dotnet.languages.csharp)