不兼容的类型错误与结构体Ç [英] Incompatible Types Error with Struct C
本文介绍了不兼容的类型错误与结构体Ç的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我如下收到一个不兼容的类型错误:
错误:分配给从类型缓存中键入'结构缓存*'时,不兼容的类型
我有以下的结构。
typedef结构__region {
INT大小;
void *的地址;
结构__region *接下来的;
}区域;typedef结构{
INT大小;
INT remainingSpace;
void *的地址;
字符*位图;
结构缓存*父母;
结构楼板*下一个;
}板;typedef结构{
INT alloc_unit;
INT slab_counter;
平板* S;
}缓存;typedef结构{
区域* R;
缓存C [8];
}内存;
在code我运行它接收错误是:
存储器M;
M.C [0] .S-&GT亲= M.C [0];
解决方案
您正在传递变量本身而不是它的地址。要通过其地址,您需要使用的地址(&安培;
)运算符:
M.C [0] .S->母公司=及(M.C [0]);
请参阅这个了解。
I am receiving an incompatible types error as follows:
error: incompatible types when assigning to type ‘struct cache *’ from type ‘cache’
I have the following structures.
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;
The code I run which receives the error is:
memory M;
M.C[0].S->parent = M.C[0];
解决方案
You are passing the variable itself not its address. To pass its address, you need to use the address of (&
) operator :
M.C[0].S->parent = &(M.C[0]);
See this for more.
这篇关于不兼容的类型错误与结构体Ç的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文