Re: GtkList number of items? gtk_object_set_data (GList)?
- From: Paul Davis <pbd Op Net>
- To: "Jean-Christophe Berthon" <jean-christophe berthon cgey com>
- Cc: "Andrés Giraldo" <andres_giraldo yahoo com>, "Gtk List" <gtk-list gnome org>
- Subject: Re: GtkList number of items? gtk_object_set_data (GList)?
- Date: Wed, 11 Jul 2001 17:31:37 -0400
>comboitem = g_malloc(sizeof(gchar)*20);
>strcpy(comboitem, "toto");
>liste = g_list_insert(liste, comboitem, (GCompareFunc) compare);
>strcpy(comboitem, "tata");
>liste = g_list_insert(liste, comboitem, (GCompareFunc) compare);
>/* ... */
this code is broken. you've just stored two instances of the same
pointer in the list; when the list is traversed, you will get:
tata
tata
not
tata
toto
don't forget to malloc more space before you pass the pointer to
G(S)List operations:
comboitem = g_malloc(sizeof(gchar)*20);
strcpy(comboitem, "toto");
liste = g_list_insert(liste, comboitem, (GCompareFunc) compare);
comboitem = g_malloc(sizeof(gchar)*20);
strcpy(comboitem, "tata");
liste = g_list_insert(liste, comboitem, (GCompareFunc) compare);
--p
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]