给出的示例是双向链表的代码的一部分。 可以说,我有以下两个给定typedefs的结构。成员使用指针访问嵌套结构。箭头运算符相当于
typedef struct dplist dplist_t;
typedef struct dplist_node dplist_node_t;
struct dplist_node {
dplist_node_t * prev, * next;
element_t element;
};
struct dplist {
dplist_node_t * head;
};
而且我在我的主要功能如下代码:
void main()
{
dplist_t * list;
dplist_node_t *node_one, *node_two;
//the arrow equivalent of the assignment
list->head = node_one;
list->head->next = node_two;
}
我知道node_one分配的“点”相当于是:
(*list).head = node_one;
但是当我尝试找到node_two赋值的“点”相当于下列所有变体似乎是错误的:
(*list).(*head).next = node_two;
(*list).*head.next = node_two;
(*list).head.next = node_two;
有没有人知道写这句话的正确方法?
'(*(* list).head).next = node_two;'。 – willys
因为head指向node_one而node_one是未初始化的指针,所以你应该调用'list-> head-> next = node_two;'来获得段错误。 – Rogus
@罗格斯这仅仅是一个例子,我只是很快写出来,没有编译或者任何东西来显示问题背后的想法。 – TheAlPaca02