Re: [gtk-list] how to free a GList filled with GStrings ?
- From: Tim Janik <timj gtk org>
- To: DROUIN Antoine STNA 7SB K232 p5766 <drouin stna dgac fr>
- cc: Gtk+ MList <gtk-list redhat com>
- Subject: Re: [gtk-list] how to free a GList filled with GStrings ?
- Date: Tue, 3 Aug 1999 23:38:09 +0200 (CEST)
On Tue, 3 Aug 1999, DROUIN Antoine STNA 7SB K232 p5766 wrote:
> GList *list = NULL;
> int beurk = TRUE;
>
>
> list = g_list_append(list, g_string_new("test1"));
> list = g_list_append(list, g_string_new("test2"));
>
> g_list_foreach(list, (GFunc)g_string_free, &beurk);
>
> I'm looking for a better way to do that (without the beurk).
> Any idea ?
you are passing the beurk *adress* as second parameter into g_string_free,
this only works because the adress is != NULL and thus assumed as a TRUE
value.
the more correct approach would be:
g_list_foreach (list, (GFunc)g_string_free, GINT_TO_POINTER (beurk));
ut that is still ugly as a variety of platform have sizeof(void*)!=
sizeof(int). so the cleanes t way to do this is:
static void free_g_string (gpointer data,
gpointer user_data)
{
g_string_free (data, GPOINTER_TO_INT (user_data));
}
g_list_foreach (list, free_g_string, GINT_TO_POINTER (TRUE));
---
ciaoTJ
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]