ListForeachPtr
- Macro
- October 8, 2025
Table of Contents
ListForeachPtr
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
Name | Direction | Description |
---|---|---|
l | in,out | List to iterate over. |
var | out | Name 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)
- In
ListInt.c:235
:
if (list->length > 0) {
int sum = 0;
ListForeachPtr(list, item_ptr) {
sum += *item_ptr;
}