Self-referential Structures (cont)
Note that the following definition does not work:
typedef struct {
int data;
NodeT *next;
} NodeT;
|
Because NodeT is not yet known (to the compiler) when
we try to use it to define the type of the next field.
The following is also illegal in C:
struct node {
int data;
struct node recursive;
};
|
Because the size of the structure would have to satisfy
sizeof(struct node) = sizeof(int) + sizeof(struct node) = ∞ .
|