I have seen questions talking about structs that have pointers to each other, I tried a lot of things but I just can't solve my problem. My brain is just, burning!
I have two different structures/types: set_t
and node_t
#ifndef _SETH_
#define _SETH_
#include "node.h"
#include "list.h"
typedef struct {
list_t* list;
}set_t;
set_t* createSet(node_t*);
set_t* findSet(node_t*);
set_t* unionSet(node_t*, node_t*);
#endif
I don't have any node_t in my set_t structure, but I use node_t as parameters, so I include node.h as you can see. List is a linked list of nodes, but this is not linked to my problem for now.
#ifndef _NODEH_
#define _NODEH_
//?? #include "set.h"
typedef struct set_t s;
typedef struct node_t{
int color;
int dist;
int key;
int date;
int end;
s* set;
struct node_t* father;
}node_t;
node_t* createNode(int);
#endif
In the beggining, I use to include set.h in node.h, because I'm using a set in my node struct. But I had some kind of "loop" with the includes. So I'im trying to use this instruction :
typedef struct set_t s;
so as to avoid the looping problem.
But this time I have another problem/warning, which I think I understand: when I do something like (let's assume we have a node_t* n):
set_t* s = (set_t*)malloc(sizeof(set_t));
n->set= s;
I have a assignement from incompatible pointer type warning, maybe because s is a set_t* but n->set is a s* ...
What am I doing wrong ? I really want to understand how this works when you want to include x.h in y.h and y.h in x.h ... Same thing if y.h needs x.h, z.h needs y.h, and x.h needs z.h .. I really hope I'm clear enough for you guys to help me.