我有數據結構訪問點內的工會內部結構 - Visual C
struct a_str {
union {
struct {
struct c_str *c;
} b_str;
struct {
int i;
} c_str;
};
}
struct c_str {
struct d_str;
}
struct d_str {
int num;
}
我試圖在結構d_str訪問NUM以下。出於某種原因,我不斷收到分段錯誤。
struct a_str *a = init_a(); //assume memory allocation and init is ok.
a->b_str.c->d_str.num = 2;
出了什麼問題?
'//假設內存分配和初始化是好的如果你遇到段錯誤,我會認爲情況並非如此。 – Nbr44
你能否向我們展示'init_a()'。 – mohit
推斷是,如果你知道問題出在什麼地方,那麼你的指針不會被初始化 – Andrew