gdl_foreach, gdl_it_idx 3 | 2016-03-06 | genlist manual |
---|
gdl_foreach - iterate over all elements of a list
gdl_foreach(gdl_list_t *list, iteratortype *iterator, itemtype *loop_elem)
gdl_it_idx(iteratortype *iterator)
gdl_foreach is a macro that evaluates to a for loop that iterates over the elements of list. It loads elem pointer loop_elem to point to the current element and updates the fields of the iterator.gdl_it_idx returns the index of the current item.
List modification in loop body:
remove previously iterated elements works, does not affect the loop remove current elements works, does not affect the loop remove the next element undefined behavior remove any element after the next element works as expected insert element anywhere before the current works (the new elements are not visited by the loop) insert right after the current works, but the new element is not visited by the loop insert after the next element works, new elements eventually visited reverse the list surprising result: the loop goes on the the original next element then takes all past elements in reverse order swap the next element with any other element undefined behavior swap any other two elements works Arguments:
list A list of which loop_elem is iterated over. May not be NULL. iterator A pointer to a gdl_iterator_t. It holds loop states. loop_elem An element pointer which is overwrittem to point to the current element in each iteration.
gdl_foreach, gdl_it_idx 3 | 2016-03-06 | genlist manual |
---|