在deque实现中检查无效指针

时间:2016-10-11 17:48:36

标签: c pointers struct

我在检查无效指针时遇到了困难。 我有一个 def bulk_edit @lead = Lead.new print "+++++++++++++++++++++++++++++++++ +++++++++++++++++++++++++++++++++ +++++++++++++++++++++++++++++++++ +++++++++++++++++++++++++++++++++ +++++++++++++++++++++++++++++++++ +++++++++++++++++++++++++++++++++ +++++++++++++++++++++++++++++++++ +++++++++++++++++++++++++++++++++ +++++++++++++++++++++++++++++++++ +++++++++++++++++++++++++++++++++ +++++++++++++++++++++++++++++++++ +++++++++++++++++++++++++++++++++ +++++++++++++++++++++++++++++++++" end 我想用它作为出队。它看起来像这样:

struct

在我的函数中,我想将一个元素推送到dequeue的末尾,我首先检查是否已经存在一个元素,如果不是,我想迭代遍历列表,直到找到具有空指针的元素为止它的下一个指针。但是,当我的循环到达空指针时,Visual Studio会在运行时停止并显示struct _dequeue_ { struct _dequeue_* next; struct _dequeue_* prev; int data; }; typedef struct _dequeue_ dequeue; 并且它不允许在那里读取。

以下是代码:

hp was 0xCCCCCCCC

所以我的问题是为什么会发生这种情况以及如何成功检查无效指针。提前谢谢!

1 个答案:

答案 0 :(得分:3)

您引用自动变量(ImageView myImage = new ImageView(this); picLL.addView(myImage); //set attributes for myImage; )。

因此,OnlyElement块完成后,if (hp == NULL) { }指针不再有效,因为hp实例已被销毁。

在堆上分配dequeue,例如:

dequeue

dequeue * OnlyElement = malloc(sizeof(dequeue)); OnlyElement->data = data; OnlyElement->next = NULL; OnlyElement->prev = NULL; hp = OnlyElement; 分配似乎也是错误的。

你可能想要这个:

dq

但是你的代码并不完整,所以这只是猜测。