g_list behavior: what am I doing wrong?
- From: Allin Cottrell <cottrell wfu edu>
- To: gtk-app-devel-list gnome org
- Subject: g_list behavior: what am I doing wrong?
- Date: Thu, 14 Jul 2005 17:23:30 -0400 (EDT)
This must be something simple, but what am I doing wrong with
g_list_prepend() below? It seems to have the effect of erasing the
original list and replacing it with a singleton element.
#include <glib.h>
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);
}
list = g_list_first(list);
list = g_list_prepend(list, "quux");
puts("\nAfter prepending:");
while (list) {
printf("list data = '%s'\n", (char *) list->data);
list = g_list_next(list);
}
return 0;
}
On my system, the first print performs as expected:
Before prepending:
list data = 'foo'
list data = 'bar'
list data = 'baz'
But the second says:
After prepending:
list data = 'quux'
???
--
Allin Cottrell
Department of Economics
Wake Forest University, NC
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]