Re: g_list problem



On Mon, 30 Sep 2002 10:28:12 +0200
Jean-Max Redonnet <jmax redonnetNOSP Mmeca insa-tlse fr> wrote:

Hello, 

I have a problem with allocation of first element in a GList. This GList 
should de declarated in the main function, but contents are computed into 
another function (included into another file). I've written a small program 
to illustrate my purpose :


The problem is that the function argument changes. The pointer must be able
to change!

the secondary file is :
#include <gtk/gtk.h>

int function(GList **list)  <---   Changed this to **list
{
      *list = g_list_append(*list, "First"); <---
      *list = g_list_append(*list, "Second"); <---
      *list = g_list_append(*list, "Third"); <---

      return 1;
}

and in the main file I put :
#include <gtk/gtk.h>

int main()
{
      GList *list = NULL;
      
      function(&list); <---
      g_print("word is %s \n", (char *)list->data);
      
      return 0;
}


This should work, I think

John

I guess you could also report the result with return


GList *function(GList *list)
{
      list = g_list_append(list, "First");
      list = g_list_append(list, "Second");
      list = g_list_append(list, "Third");

      return list;
}

in main()

        list = function(list);



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