Re: GList



On 05/02/2005 01:13:49 PM, ÐÐÑÐÐÐÐÑÐÐ ÐÐÐÐÑ wrote:
i think that the result of next code must be 3.
but i have 0

...because l is still NULL, and g_list_length(NULL) is 0. g_list_append returns the address of the first item in the list with its appended item, so you should use:

if uncomment "l=..." it's work correctly

#include <glib.h>

int main()
{
    GList* l=NULL;
//    l=g_list_alloc();

      l = g_list_append(l,GINT_TO_POINTER(1));
      l = g_list_append(l,GINT_TO_POINTER(1));
      l = g_list_append(l,GINT_TO_POINTER(1));


    printf("%i",g_list_length(l));
}



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