Difference between pages "r6:Function:slist get head and then next" and "r6:Function:slist get next"

From liblfds.org
(Difference between pages)
Jump to navigation Jump to search
m (1 revision imported)
 
m (1 revision imported)
 
Line 4: Line 4:


==Prototype==
==Prototype==
  struct slist_element *slist_get_head_and_next( struct slist_state *ss, struct slist_element **se );
  struct slist_element *slist_get_next( struct slist_element *se, struct slist_element **next_se );


==Parameters==
==Parameters==
''struct slist_state *ss''
''struct slist_element *se''
: An slist state as allocated by ''[[r6:Function:slist_new|slist_new]]''.
: A pointer to an slist element, as obtained from ''[[r6:Function:slist_new_head|slist_new_head]]'', ''[[r6:Function:slist_new_next|slist_new_next]]'', ''[[r6:Function:slist_get_head|slist_get_head]]'', ''slist_get_next'' or ''[[r6:Function:slist_get_head_and_then_next|slist_get_head_and_then_next]]''.


''struct slist_element **se''
''struct slist_element **next_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).
: A pointer to a pointer into which a pointer to the next slist element will be placedSet to NULL if there is no next element.


==Return Value==
==Return Value==
When ''*se'' is NULL, ''*se'' is set to point to the head element and the new value of ''*se'' is returned.
Returns a pointer to the next element.  Returns NULL if there is no next element.
 
When ''*se'' is not NULL, ''*se'' is set to point to the element immediately after ''*se'' and the new value of ''*se'' is returnedThis value will be NULL if there was no element after the original value of ''*se''.


==Notes==
==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.
It is acceptable (and expected to often occur) to use the same variable for both arguments, e.g.
 
Without this function, the ''slist_get_head'' function must be used before the loop, with the ''slist_get_next'' function being then used inside the loop, like so;
 
struct slist_element
  *se;
slist_get_head( ss, &se );
while( se != NULL )
{
    ...
    slist_get_next( se, &se );
}
 
With it, the loop is rewritten thus;


  strut slist_element
  slist_get_next( se, &se );
  *se = NULL;
while( slist_get_head_and_then_next(ss, &se) )
{
    ...
}


==See Also==
==See Also==
* [[r6:API:SList|SList]]
* [[r6:API:SList|SList]]
* [[r6:Function:slist_get_head|slist_get_head]]
* [[r6:Function:slist_get_head|slist_get_head]]
* [[r6:Function:slist_get_next|slist_get_next]]
* [[r6:Function:slist_get_head_and_then_next|slist_get_head_and_then_next]]

Latest revision as of 14:07, 4 January 2015

Source Files

/src/slist/slist_get_and_set.c
/inc/liblfds.h

Prototype

struct slist_element *slist_get_next( struct slist_element *se, struct slist_element **next_se );

Parameters

struct slist_element *se

A pointer to an slist element, as obtained from slist_new_head, slist_new_next, slist_get_head, slist_get_next or slist_get_head_and_then_next.

struct slist_element **next_se

A pointer to a pointer into which a pointer to the next slist element will be placed. Set to NULL if there is no next element.

Return Value

Returns a pointer to the next element. Returns NULL if there is no next element.

Notes

It is acceptable (and expected to often occur) to use the same variable for both arguments, e.g.

slist_get_next( se, &se );

See Also