r6.1.0:lfds610_slist_get_head_and_then_next

From liblfds.org
Jump to navigation Jump to search

Source Files

/liblfds610/src/lfds610_slist/lfds610_slist_get_and_set.c
/liblfds610/inc/liblfds610.h

Prototype

struct lfds610_slist_element *lfds610_slist_get_head_and_next( struct lfds610_slist_state *ss, struct lfds610_slist_element **se );

Parameters

struct lfds610_slist_state *ss

An slist state as allocated by lfds610_slist_new.

struct lfds610_slist_element **se

A pointer to a pointer which will be set to point to an slist element. When this function is first called, *se must be NULL (e.g. the value of the pointer pointed to by this argument must be NULL).

Return Value

When *se is NULL, *se is set to point to the head element and the new value of *se is returned.

When *se is not NULL, *se is set to point to the element immediately after *se and the new value of *se is returned. This value will be NULL if there was no element after the original value of *se.

Notes

This function is for use in loops. When we first come into the loop, we have set *se to NULL, so the function sets *se to the head element. When we loop, because *se is not NULL, the function there-after sets *se to the next element in the list.

Without this function, the lfds610_slist_get_head function must be used before the loop, with the lfds610_slist_get_next function being then used inside the loop, like so;

struct lfds610_slist_element
  *se;

lfds610_slist_get_head( ss, &se );

while( se != NULL )
{
   ...

   lfds610_slist_get_next( se, &se );
}

With it, the loop is rewritten thus;

strut lfds610_slist_element
  *se = NULL;

while( lfds610_slist_get_head_and_then_next(ss, &se) )
{
   ...
}

See Also