RE: passing glist to func



I believe this is due to g_list_append() moving the address of your glist
after it allocates space for it.  Therefore "list" is pointing to the old
memory location, and "a" is pointing to the new location.  A simple test to
confirm this would be to set foo() to return GList *a and set "list" to this
return value.



                                -- Stupid Genius

----------
From:
revans ozarkaircraftsystems com[SMTP:revans ozarkaircraftsystems com]
Sent:         Monday, October 09, 2000 8:54 AM
To:   gtk-app-devel-list gnome org
Subject:      passing glist to func


Please forgive my ignorance, but could someone explain why this doesn't
work? I want to pass a pointer to a glist to a function and modify that
glist there. The following program prints the value of "a" in function foo
then gives a Segmentation fault trying to print the value of "list" in
main.

Thanks
--------------------------
#include <glib.h>
#include <stdio.h>


void foo(GList *a)
{
  a=g_list_append(a, "text");
  a=g_list_first(a);
  printf("a=%s\n", (char *) a->data);
}

int main()
{
  GList *list=NULL;
  foo(list);
  list=g_list_first(list);
  printf("list=%s\n", (char *) list->data);
  return 0;
}


_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list





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