Ah, I see. Thanks for showing that pitfall, I could easily have done
the same thing.

Cheers,
Chris Anderson

On 7/14/05, Allin Cottrell <[EMAIL PROTECTED]> wrote:
> On Thu, 14 Jul 2005, Christopher Anderson wrote:
> 
> > I am curious, could you explain your solution?
> 
> OK, at the cost of some embarrassment ;-)
> 
> Quoting my test function:
> 
> int main (void)
> {
>       GList *list = NULL;
> 
>       list = g_list_append(list, "foo");
>       list = g_list_append(list, "bar");
>       list = g_list_append(list, "baz");
> 
>       puts("\nBefore prepending:");
> 
>       while (list) {
>         printf("list data = '%s'\n", (char *) list->data);
>         list = g_list_next(list);
>       }
> 
> Bzzzt!!  On the first iteration of the above printing loop I lose
> the true start of "list".  I should have used a temporary variable
> for looping over the list elements, as in
> 
>       GList *tmp = list;
> 
>       while (tmp) {
>          printf("list data = '%s'\n", (char *) tmp->data);
>          tmp = g_list_next(tmp);
>       }
> 
> Or I suppose I could have used g_list_foreach() with a callback
> function, though I find that a bit awkward.
> 
> Allin Cottrell
> 
>
_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

Reply via email to