ListForeachPtrReverseInRange
Description
Iterate over each element var (as a pointer) 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 as a pointer to the list’s data type.
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,out | List to iterate over. |
var |
out | Name of the pointer variable to be used which will point to 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 the in-node data address. Use this form when the body mutates elements in place. The body is skipped when the range 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:356:
if (start < end) {
int sum = 0;
ListForeachPtrReverseInRange(list, item_ptr, start, end) {
sum += *item_ptr;
} }
ListForeachPtrReverseInRange(&list, value_ptr, 1, 4) {
*value_ptr /= 2;
} }
ListForeachPtrReverseInRange(&list, value_ptr, 8, 10) {
(void)value_ptr;
count += 1000; }
ListForeachPtrReverseInRange(&list, value_ptr, 0, 1) {
(void)value_ptr;
count += 10000000;