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

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

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

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

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

gtk-app-devel-list mailing list
gtk-app-devel-list gnome org

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