Skip to content

ListPopBack

Description

Remove the last 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 tail node is unlinked, its allocator-owned storage freed; list length shrinks by one, the previous node becomes the new tail. 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)
                if (ListLen(list) > 0) {
                    i32 popped;
                    ListPopBack(list, &popped);
                }
                break;
        result = result && list_matches(GENERIC_LIST(&list), (const int[]) {30, 40}, 2);
    
        ListPopBack(&list, &removed);
        result = result && (removed == 40);
        result = result && list_matches(GENERIC_LIST(&list), (const int[]) {30}, 1);
    
    static bool test_list_pop_back_empty_fails(void) {
        WriteFmt("Testing ListPopBack on empty list\n");
    
        List(int) list = ListInit(get_test_alloc());
    
        List(int) list = ListInit(get_test_alloc());
        ListPopBack(&list, NULL);
    
        return false;
    /// TAGS: List, Delete, Back
    ///
    #define ListDeleteLast(l) ListPopBack((l), NULL)
    
    ///
Last updated on