ListForeachPtr

Table of Contents

ListForeachPtr

Description

Iterate over each element var (as a pointer) of the given list l. The variable var is declared and defined by this macro as a pointer to the list’s data type. Iteration happens in forward order, starting from the head of the list and continuing through the next pointers until the end is reached. The variable var will point to the data associated with each list node.

Parameters

NameDirectionDescription
lin,outList to iterate over.
varoutName of the pointer variable to be used which will point to the current element during iteration. The type of var will be a pointer to the data type of the list elements (i.e., LIST_DATA_TYPE(l) *).

Usage example (Cross-references)

    if (list->length > 0) {
    int sum = 0;
    ListForeachPtr(list, item_ptr) {
    sum += *item_ptr;
    }

Share :

Related Posts

ListForeach

ListForeach Description Iterate over each element var of the given list l. The variable var is declared and defined by this macro. Iteration happens in forward order, starting from the head of the list and continuing through the next pointers until the end is reached. The variable var will contain a copy of the value pointed to by each list node.

Read More

VecForeachReverse

VecForeachReverse Description Iterate over each element var of the given vector v in reverse order. This is a convenience macro that iterates backward using an internally managed index. The variable var is declared and defined by this macro.

Read More

VecForeachInRangeIdx

VecForeachInRangeIdx Description Iterate over elements in a specific range of the given vector v at each index idx. The variables var and idx are declared and defined by this macro. idx will start from start and will go till end - 1

Read More