Solaris Software
Loading...
Searching...
No Matches
structof.h File Reference

Container-of macro for intrusive data structures. More...

#include <stddef.h>
Include dependency graph for structof.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define SPP_STRUCTOF(p_member, type, member)
 Recover a pointer to the containing struct from a member pointer.

Detailed Description

Container-of macro for intrusive data structures.

Allows recovering a pointer to the enclosing struct from a pointer to one of its members — enabling zero-overhead intrusive lists and trees without extra allocations, as used in lely-core.

Naming conventions used in this file:

  • Macros: SPP_STRUCTOF

Definition in file structof.h.

Macro Definition Documentation

◆ SPP_STRUCTOF

#define SPP_STRUCTOF ( p_member,
type,
member )
Value:
((type *)((char *)(p_member) - offsetof(type, member)))

Recover a pointer to the containing struct from a member pointer.

Parameters
p_memberPointer to the member field.
typeType of the containing struct.
memberName of the member field inside type.
Returns
Pointer to the enclosing type instance.

Example:

typedef struct { int x; ListNode_t node; } MyItem_t;
ListNode_t *p_node = ...;
MyItem_t *p_item = SPP_STRUCTOF(p_node, MyItem_t, node);
#define SPP_STRUCTOF(p_member, type, member)
Recover a pointer to the containing struct from a member pointer.
Definition structof.h:34

Definition at line 34 of file structof.h.