ListForeachPtrReverse
Description
Iterate over each element var (as a pointer) of the given list l in reverse order. The variable var is declared and defined by this macro as a pointer to the list’s data type.
Iteration happens in reverse, starting from the tail of the list and continuing through the prev pointers until the head 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) *). |
Success
The loop body runs once for each node from 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 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:286:
if (ListLen(list) > 0) {
int sum = 0;
ListForeachPtrReverse(list, item_ptr) {
sum += *item_ptr;
} }
ListForeachPtrReverse(&list, value_ptr) {
*value_ptr -= 1;
} }
ListForeachPtrReverse(&list, value_ptr) {
(void)value_ptr;
count += 1000;
Last updated on