ListForeachReverseInRange
Description
Iterate over each element var of the given list l in reverse, limited to index range [start, end) relative to the tail of the list. Index 0 corresponds to the tail, 1 to the previous node, and so on.
The variable var is declared and defined by this macro.
Since linked lists do not support indexing, this macro counts nodes from the tail and includes only those where the relative reverse index lies in [start, end).
Parameters
| Name | Direction | Description |
|---|---|---|
l |
in | List to iterate over. |
var |
in,out | Name of the variable to be used which will contain the value of the current element during iteration. |
start |
in | Starting index from tail (inclusive). |
end |
in | Ending index from tail (exclusive). |
Success
The loop body runs once for each node whose tail-relative index lies in [start, end) while walking tail-to-head, with var bound to a copy of that node’s data. The body is skipped when the range is empty or l is empty.
Failure
The macro itself does not fail. LOG_FATAL via ValidateList(l) when l is uninitialised or corrupted.
Usage example (Cross-references)
Usage examples (Cross-references)
- In
ListInt.c:341:
if (start < end) {
int sum = 0;
ListForeachReverseInRange(list, item, start, end) {
sum += item;
} }
ListForeachReverseInRange(&list, value, 1, 4) {
reverse_range_sum += value;
} }
ListForeachReverseInRange(&list, value, 3, 3) {
(void)value;
count += 100; }
ListForeachReverseInRange(&list, value, 4, 2) {
(void)value;
count += 100000; }
ListForeachReverseInRange(&list, value, 0, 1) {
(void)value;
count += 1000000;
Last updated on