Re: double linked list question.

On Thu, 21 Dec 2000, Jeff Shipman wrote:

> On Tue, 5 Dec 2000, Elias Athanasopoulos wrote:
>> Hi,
>> Is there a known problem when removing the first element of a double
>> linked list (GList)? I am facing a core dump, when I loop the
>> list (after I have removed the first element), something that is not
>> happening if I remove the nth element (n != 1).
>> I can show you my code, if you like. I'm asking, just in case there is a
>> known issue, or maybe it's better to have a second look in my work. :-)
>> Regards,
>> Elias
>> PS. Please cc me, as I am not subscribed.
> I've never experienced anything like this. Would you
> mind sending your code to the list?

I couldn't find the original post, but I suspect you forget to reassign the
list.  Note the return type of the prototype:

GList*      g_list_remove (GList *list, gpointer data);

The new list is returned, because the list pointer points to the first
element to the list.  So if you do

  GList *my_list = make_list_somehow(some_data, some_other_data);
  g_list_remove(my_list, some_data);

you're passing a NULL pointer to do_something (at best).  You must reassign
the list to take care of the case when you remove the first element:

  GList *my_list = make_list_somehow(some_data, some_other_data);
  my_list = g_list_remove(my_list, some_data);



Lars Clausen ( | Hårdgrim of Numenor
"I do not agree with a word that you say, but I    | Retainer of Sir Kegg
will defend to the death your right to say it."    |   of Westfield
    --Evelyn Beatrice Hall paraphrasing Voltaire   | Chaos Berserker of Khorne

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]