When creating a self-referencing data type, you need to use pointers to solve roundness problems:
struct node; struct node { struct node * next; int id; }
... should work, but try to allocate memory correctly when using it.
Why a pointer? Consider this: the struct definition point is that the compiler can determine how much memory to allocate and what parts of access when you say node.id If your node structure contains a different node structure, how much memory should the compiler allocate for the given node ?
Using a pointer, you get around this because the compiler knows how much space is allocated for the pointer.
source share