结构C的类型错误不兼容

我收到一个不兼容的类型错误如下:

error: incompatible types when assigning to type 'struct cache *' from type 'cache' 

我有以下结构。

 typedef struct __region { int size; void *addr; struct __region *next; } region; typedef struct { int size; int remainingSpace; void *addr; char *bitmap; struct cache *parent; struct slab *next; } slab; typedef struct { int alloc_unit; int slab_counter; slab *S; } cache; typedef struct { region *R; cache C[8]; } memory; 

我运行的接收错误的代码是:

 memory M; MC[0].S->parent = MC[0]; 

您传递变量本身而不是其地址。 要传递其地址,您需要使用( & )运算符的地址:

 MC[0].S->parent = &(MC[0]); 

有关更多信息,请参阅

parent是指向struct cache的指针,而MC[0]struct cache 。 您可以使用&运算符来获取指向MC[0]的指针,如下所示:

 MC[0].S->parent = &(MC[0]);