Re: gtk_object_set_data (GList)?



Hi,

"AndrXs" Giraldo <andres_giraldo yahoo com> writes:

> typedef _data
>   {
>     char *string;
>     int value;
>   } data;
> 
> data comboitem;
> 
> GList *liste = NULL;
> 
> >   comboitem = g_malloc(sizeof(struct _data));
> >   strcpy(comboitem.string, "toto");
> >   liste = g_list_insert(liste, comboitem, 0);
> > 
> >   comboitem = g_malloc(sizeof(struct _data));
> >   strcpy(comboitem.string, "tata");
> >   liste = g_list_insert(liste, comboitem, 0);

this code should probably read:

  typedef struct _data
  {
    char *string;
    int value;
  } data;
 
  data *comboitem;

  GList *liste = NULL;

  comboitem = g_new (data, 1);
  comboitem->string = g_strdup ("toto");
  liste = g_list_prepend (liste, comboitem);
 
  comboitem = g_new (data, 1);
  comboitem->string = g_strdup ("tata");
  liste = g_list_prepend (liste, comboitem);


don't forget to free your strings again (using g_free).


Salut, Sven





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