You can use a forward declaration of the struct
typedef struct sNode Node; // this is a typedef and a declaration of the struct
struct sNode{
int data;
Node *next;
Node *prev;
};
This way Node
is known (but not defined), in the definition of your struct
.
This can be compressed as it is done by Yunnosch. But then you need to use the struct Name
notation inside your declaration.
This way it is possible to already use the typedefed name also the forward declaration is necessary if you have some circular dependencies in your structs.
It is also possible to use the struct name as the typedef:
typedef struct Node Node;
struct Node{
int data;
Node *next;
Node *prev;
};
I personally prefer the first style, it seems "clearer" to me, but there is nothing wrong with the second example, as long as the compiler is not from the pre-standard era (before 1989).
As Jens Gustedt pointed out the first style might be incompatible if this is included in C++.
So maybe I should change my preference to the first.