Re: how to free a GList filled with GStrings ?




DROUIN Antoine STNA 7SB K232 p5766 <drouin@stna.dgac.fr> writes:

> 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 ?

Well, the 'beurk' isn't correct, since the second
parameter isn't a pointer to an int, it is an int.

On some platforms, it work work to do:

  g_list_foreach(list, (GFunc)g_string_free, GINT_TO_POINTER (TRUE));

However, this isn't portable, and will break horribly on
some architectures. What you should do is simply use a helper
function:

 void
 free_string (gpointer string, gpointer data)
 {
   g_string_free (string, NULL);
 }

 g_list_foreach (list, free_string, NULL);

 
> By the way, does anybody know if it's possible to have an app display on two 
> screens ? (two X servers on two different machines)

It's not currently possible with GTK+. (You'd have to
have two programs talking to each other via IPC)

Regards,
                                        Owen



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