相互引用的结构

1 c struct

我有两个需要相互引用的结构,但是无论我先放置哪个结构都会抛出错误,因为我使用的是未识别的类型。

typedef struct _BLOCK
{
    int size;
    int offset;
    struct _BLOCK *nextBlock;
    struct _BLOCK *prevBlock;
    Pool* parent;  //here
} Block;

typedef struct _POOL
{
    int size;
    void* memory;
    Block* Allocated;
    Block* Unallocated;
} Pool;
Run Code Online (Sandbox Code Playgroud)

有什么方法可以解决这个问题吗?

Mik*_*CAT 5

您可以使用前向声明。

typedef struct _POOL Pool;

typedef struct _BLOCK
{
    int size;
    int offset;
    struct _BLOCK *nextBlock;
    struct _BLOCK *prevBlock;
    Pool* parent;
} Block;

struct _POOL
{
    int size;
    void* memory;
    Block* Allocated;
    Block* Unallocated;
};
Run Code Online (Sandbox Code Playgroud)