List question

Hello all,

I was just looking at the source for glist.c and a thought occurred to me (which happens on occasion).  ;)  What if the client passes a pointer to the tail of the list, or any arbitrary node within the list, to some of these functions?  Would this break some functions, cause them to fail, or operate in unexpected ways?

For example,

    GList* node = NULL;
    GList* head = NULL;
    /* Add several nodes... */
    GList* tail = g_list_last (head);

    /* Does this actually prepend to the head of the list?
    node = g_list_prepend (tail, data);

    /* Is this the actual length of the list?
    int len = g_list_length (node);

For efficiency reasons, I can see why the list functions may require that the 'list' parameter is the head of the list but, for sake of argument, why should some of these functions assume that?  Or maybe this policy should just be reiterated in the documentation somewhere.


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