我是新来的C,我不能弄清楚,为什么我收到初始化不相容poniter型warning.The代码的相关部分:编译器警告:初始化兼容的指针类型
struct a {
int address;
B * apples[8];
} A;
struct b {
int color;
} B;
我有一个名为a_list的A数组。什么我目前做的是:
B *b_list = a_list[i].apples; // i being an index in for loop
b_list[6].color = 0;
上述工作正常,但抛出的警告:
Initialization from incompatible pointer type.
为了解决这个问题,我的理由是我应该做的
B ** b_list = a_list[i].apples; // as it is pointer to pointer.
So now b_list basically points to a pointer which points to an array of 6, yea?
So: (*b_list)[6].color // However this causes segmentation fault.
当结构体A有B苹果[8]而不是B *苹果[8]时,它也正常工作。但是,使用这种解决方案并不能将功能所做的更改保留在制定位置之外。
请指教。
上述两者都会导致分段错误。是否因为有些街区没有搭配? – Catie
@Catie:你有没有分配数组中的每个'B'? –