ListForeachReverseIdx
- Macro
- October 8, 2025
Table of Contents
ListForeachReverseIdx
ListForeachReverseIdxDescription
Iterate over each element var of the given list l in reverse order, with index idx. The variable var is declared and defined by this macro. Iteration starts from the tail and moves backward using the prev pointers. The variable idx will contain the zero-based index from the head: index length-1 corresponds to the tail, length-2 to the previous node, and so on down to 0 (head).
Info
The macro supports iteration using relative traversal if random access is required. This means user code can change idx to any value in list boundaries and the macro will adjust node automatically for the new index.
Parameters
| Name | Direction | Description |
|---|---|---|
l | in | List to iterate over. |
var | out | Name of the variable to hold the value during iteration. |
idx | out | Variable that will track the index from the head. |
Usage example (Cross-references)
- In
ListInt.c:268:
if (list->length > 0) {
int sum = 0;
ListForeachReverseIdx(list, item, idx) {
sum += item + (int)idx;
}