RE: do I really understand this or not ?

No, the routine is right.  The HTList is in backwards order so that the
first item in the list is at the end of the chain.  The last item in the
list is the first in the chain.  (Unless it was sorted.)  While there is
extraneous code, the code is right.  It looks like it is copied from the
HTList_removeFirstObject routine above it.  If you remove the extraneous
stuff you get:
PUBLIC void * HTList_firstObject  (HTList * me)
{
    if (me && me->next) {
        while (me->next)
            me = me->next;
        return me->object;
    } else
        return NULL;
}

Your routine is actually returning the last object in the list.  This would
be the routine which does not exist called HTList_lastObject:
PUBLIC void * HTList_lastObject  (HTList * me)
{
    if (me && me->next)
     {
      return me->next->object;
     }
    return NULL;
}
-----Original Message-----
From: Gregory Nicholls [mailto:gnicholls@level8.com]
Sent: Thursday, June 08, 2000 3:00 PM
To: www-lib@w3.org
Subject: do I really understand this or not ?


Hi,
 I've found something odd with the HTList_firstObject() function. My
read on this is that it should return a pointer to the first object in
the list. Running some tests shows that this doesn't happen.
  After looking at the source it seems (to my naive eye) that this
routine will always return NULL.
    Here's the source I have with a mod that I put in to make it work
the way I _think_ it's supposed to.
Could someone more knowledgable please comment on this please ?

    Thanks,
        G
--------------- snip -----------------------
PUBLIC void * HTList_firstObject  (HTList * me)
{
/* This is the original code
    if (me && me->next) {
        HTList * prevNode;
        while (me->next) {
            prevNode = me;
            me = me->next;
        }
        return me->object;
    } else
        return NULL;
*/
/* This is my new stuff */
    if (me && me->next)
     {
      return me->next->object;
     }
    return NULL;
}

Received on Thursday, 8 June 2000 16:11:51 UTC