Re: [gtk-list] Re: g_list_insert_sorted bug



On Wed, 1 Jul 1998, Ian McKellar wrote:

> After breif experimentation, the broblem seems to be a bit more widespread. It
> seems that there is a NULL item in every GList. g_list_foreach calls my
> function with NULL too.

Yes, the way GList is implemented, each list starts off with a NULL first
item.  This is not necessarily a bug, it's just part of g_list's algorithm.  
There are a couple of ways to get around this:
  1. Since the first item is always NULL, use g_list_prepend instead of
     _append.  This will move the NULL to the end of the list so you don't
     have to deal with it (it can be an 'end of list' type marker).
  2. Whenever you have a g_list_foreach callback, just test for null and
     skip past that item if it is null.
There are list algorithms that utilize the whole list without placing a
NULL in the first item, but apparently glib doesn't implement it that way.

---
Matt Perry [guy@mikepery.linuxos.org]

I'd give my right arm to be ambidextrous.
---



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