ListPopFront
Description
Remove the first element of the list and optionally store its value.
Parameters
| Name | Direction | Description |
|---|---|---|
l |
in,out | List handle. |
val |
out | Optional destination for the popped element. |
Success
Returns to the caller. The head node is unlinked, its allocator-owned storage freed; list length shrinks by one, the next node becomes the new head. When val is non-NULL the removed value is memcopied into *val.
Failure
Function cannot fail. Calling on an empty list is a caller bug and aborts via LOG_FATAL.
Usage example (Cross-references)
Usage examples (Cross-references)
- In
ListInt.c:59:
if (ListLen(list) > 0) {
i32 popped;
ListPopFront(list, &popped);
}
break;- In
List.Remove.c:62:
result = result && list_matches(GENERIC_LIST(&list), (const int[]) {10, 30, 40}, 3);
ListPopFront(&list, &removed);
result = result && (removed == 10);
result = result && list_matches(GENERIC_LIST(&list), (const int[]) {30, 40}, 2);
static bool test_list_pop_front_empty_fails(void) {
WriteFmt("Testing ListPopFront on empty list\n");
List(int) list = ListInit(get_test_alloc());
List(int) list = ListInit(get_test_alloc());
ListPopFront(&list, NULL);
return false;
Last updated on