This is my first post on this board, so I would first like to say hello to everybody here!
I want to program a directed graph datastructure. OK, so here are my two types: edges and nodes:
Further, I have these functions for memory allocation on the heap.
unsigned int n_e; // number of connected edges
struct edge_struct **e; // array of connected edges (array of pointers to edges)
typedef struct node_struct node;
float c; // capacity
float f; // flow
node * u; // start
node * v; // end
typedef struct edge_struct edge;
Well, ok, this compiles fine (under MS VS 2003 Pro), with this main function:
node ** u,
unsigned int n
*u = ((node)*) malloc(sizeof(node));
if(*u == NULL)
printf("alloc_node: (1) Not enough storage available.\n");
(*u)->n_e = n;
(*u)->e = (edge**) malloc(n * sizeof(edge*));
if ((*u)->e == NULL)
printf("alloc_node: (2) Not enough storage available.\n");
*e = ((edge)*) malloc(sizeof(edge));
if(*e == NULL)
printf("alloc_edge : Not enough memory available.\n");
(*e)->c = 0.0f;
(*e)->f = 0.0f;
(*e)->u = 0;
(*e)->v = 0;
But if I uncomment the second line, then the compiler complains with
node * v1;
edge * a;
f:\src\main.c(18): error C2275: 'edge' : illegal use of this type as an expression
where line 18 eaxtly points to the line holding "edge * a;", so not the call to alloc_node.
But as I said, if I comment the call to the alloc_node, everything compiles fine.
I don't know where my error lies.
Thanks a lot in advance!