Skip to content

CF_LIST_HOST

Category: list
GitHub: cute_doubly_list.h


Converts a pointer to a node to a pointer to its host struct/object.

#define CF_LIST_HOST(T, member, ptr) ((T*)((uintptr_t)ptr - CF_OFFSET_OF(T, member)))
Parameters Description
T The type of the host.
member The name of the host member.
ptr A pointer to the host.

Return Value

Returns a pointer to a the host struct/object of type T.

Code Example

Converting from node to host pointer.

struct MyStruct {
    int a;
    float b;
    CF_ListNode node;
};

CF_ListNode node_ptr = get_node();
MyStruct my = CF_LIST_HOST(MyStruct, node, node_ptr);

// Do whatever is needed with the host:
do_stuff(my);

Remarks

This doubly-linked list is intrusive, meaning you place nodes inside of objects. These helper macros are to easily convert to/from host pointer and node pointer.

CF_ListNode
CF_List
CF_LIST_NODE
cf_list_back
cf_list_init_node
cf_list_init
cf_list_push_front
cf_list_push_back
cf_list_remove
cf_list_pop_front
cf_list_pop_back
cf_list_empty
cf_list_begin
cf_list_end
cf_list_front