我决定在这个程序中使用结构来保持它的组织性,所以我现在有一个结构链。我的问题是我是否必须 malloc 一个位于另一个结构中的结构。例如:
typedef struct OnlineS {
struct BBSIS *bbsi;
struct BBVIS *bbvi;
struct VBVIS *vbvi;
} *OnlineP;
typedef struct BBSIS{
struct FirstFitS *ff;
struct BestFitS *bf;
struct NextFitS *nf;
int itemNum;
int binNum;
int binMin;
int binMax;
int *items;
}*BBSIP;
依此类推,我的声明和 malloc 会是什么样子?
OnlineP on = malloc(sizeof (struct OnlineS));
on->bbsi = malloc(sizeof (struct BBSIS));
on->bbsi->bf = malloc(sizeof (struct BestFitS));
on->bbsi->nf = malloc(sizeof (struct NextFitS));
on->bbsi->ff = malloc(sizeof (struct FirstFitS));
on->bbvi = malloc(sizeof (struct BBVIS));
on->bbvi->bf = malloc(sizeof (struct BestFitS));
//ETC