ListForeachReverse
Description
Iterate over each element var of the given list l in reverse order. The variable var is declared and defined by this macro.
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 contain a copy of the value pointed to by each list node.
Parameters
| Name | Direction | Description |
|---|---|---|
l |
in | List to iterate over. |
var |
out | Name of the variable to be used which will contain the value of the current element during iteration. The type of var will be the data type of the list elements (obtained via LIST_DATA_TYPE(l)). |
Success
The loop body runs once for each node from tail to head with var bound to a copy of that node’s data. 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:264:
if (ListLen(list) > 0) {
int sum = 0;
ListForeachReverse(list, item) {
sum += item;
} }
ListForeachReverse(&list, value) {
reverse_values[reverse_i++] = value;
} }
ListForeachReverse(&list, value) {
(void)value;
count += 100;
Last updated on