结构体中的链表初始化方法
#include <stdio.h>
struct list_head {
struct list_head *next, *prev;
};
struct teacher_list{
struct list_head sport;
struct list_head english;
struct list_head maths;
};
struct stu {
struct teacher_list teachers_1;
struct teacher_list teachers_2;
};
#define LIST_HEAD_INIT(name) { &(name), &(name) }
#define TEACHERS_LIST_INIT(parent) \
{ \
.sport = LIST_HEAD_INIT(parent.sport), \
.english = LIST_HEAD_INIT(parent.english), \
.maths = LIST_HEAD_INIT(parent.maths) \
}
int main()
{
struct stu xiaoming = {
.teachers_1 = {
.sport = {&xiaoming.teachers_1.sport, &xiaoming.teachers_1.sport},
.english = {&xiaoming.teachers_1.english, &xiaoming.teachers_1.english},
.maths = {&xiaoming.teachers_1.maths, &xiaoming.teachers_1.maths}
},
.teachers_2 = TEACHERS_LIST_INIT(xiaoming.teachers_2)
};
原文地址:https://blog.csdn.net/zhu_superman/article/details/143695295
免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!