GLists & Sorting




This is my first usage of GLib and GTK. I have used similar before.

Here is some code:

      g_list_foreach(filesystems,printlistelement,NULL);
      g_message("There are  %d elements.\n",g_list_length(filesystems));
      if(filesystems && bsort)
         g_list_sort(filesystems,comparenames);
      g_message("There are  %d elements.\n",g_list_length(filesystems));

The 1st and second line correctly print out the 17 list contents and the
number of elements respectively.
The list contains GStrings. printlistelemet is defined as:

void printlistelement(gpointer r1, gpointer ignore){
   g_message("%s\n",((GString *)r1)->str);
}

The next call to g_list_length gave 3 instaed of 17!

Where I had my problem was where I did not reassign the output of the call
to g_list_sort to "filesystems". What is the thinking behind this in the
API? If I had a pointer to a List "object" then it should be just that - not
a pointer to a sub element.


-- 
View this message in context: http://www.nabble.com/GLists---Sorting-tf2837253.html#a7921273
Sent from the Gtk+ - General mailing list archive at Nabble.com.




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