Re: glib slist question



on 3/29/00 2:02 PM, jay at mocat@qpt.com wrote:

> I've never worked too in depth with void pointers, so this problem is
> baffling me.
> 
> here's a little (hypothetical) code snippet that illustrates what i'm
> trying to do - add an array of strings to a GSList.
> 
>     GSList *list = NULL;
>     gchar *append[] { "one","two","three","four" };
> 
>     list = g_slist_append(list, append);
> 
> This works fine, but how would I go about dereferencing, say, element
> 2 of the array I just inserted?
> 
> I've tried list->data[2] with various casts, but whatever I do I get a
> compiler error.

You'd have to case the data pointer back to an array of char *, which in C
is roughly the same as a pointer to char *. The easiest way would be:

    ((char **) list->data)[2]

But this question is quite inappropriate for the Gtk Developers list. This
is a list for discussion about the development _of_Gtk_itself_. You want
gtk-app-devel, but since this is a generic C question, it might not even be
right for that list.

    -- Darin



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