member access within misaligned address 0x000000000031 for type 'struct ListNode', which requires 8

来源:互联网 发布:淘宝店家虚假发货 编辑:程序博客网 时间:2024/06/07 08:06

错误提示:

member access within misaligned address 0x000000000031 for type 'struct ListNode', which requires 8 byte alignment

原因分析:

在链表中,链表节点定义如下:

Definition for singly-linked list. * struct ListNode { *     int val; *     struct ListNode *next;  * };
在申请空间时代码如下:

temp1=(struct ListNode*)malloc(sizeof(struct ListNode));
由于结构体内存在next指针,而申请结构体空间后同时定义了next指针,此时next指针未指向任何空间,故在测试时可能导致上述错误。

解决方法为:

增加代码使next指针指向空。

temp->next=NULL;


0 0