Re: G_LIST_REMOVE not working... at least not for me :-)



Ahhh... I see!  Thank you.  That makes perfect sense. 
This doesn't seem to be explained very well in the
documentation, and the few examples I was able to find
were not documented well enough to figure this out.

Thanks!

Mike

--- Havoc Pennington <hp redhat com> wrote:

On Sat, Nov 16, 2002 at 03:50:05PM -0800, Mike
Dailey wrote:

mainConnMgmtComboList = g_list_remove
(mainConnMgmtComboList,
g_strdup(FMC->appCURMGMTHOST.c_str()));

C doesn't work this way; it doesn't know what the
void* in the 
GSList points to. You have to remove the string
using exactly the 
same pointer used to add the string.

GList*
remove_string_by_value (GList *list, const char
*str)
{
  GList *iter;
  iter = list;
  while (iter != NULL)
    {                   
      const char *s = iter->data;
      if (strcmp (s, str) == 0)
        return g_list_remove (list, iter->data);
      iter = iter->next;
    }
  return list;
}

You can make it more efficient by unlinking the list
node "iter" when
the string matches, instead of using g_list_remove
which scans from
the front of the list, but it's somewhat more
tricky.

Havoc



__________________________________________________
Do you Yahoo!?
Yahoo! Web Hosting - Let the expert host your site
http://webhosting.yahoo.com



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