Skip to content

Instantly share code, notes, and snippets.

@kyoungho-koo
Last active April 8, 2018 15:41
Show Gist options
  • Save kyoungho-koo/077fafdb45775d1522c5dae194b0adef to your computer and use it in GitHub Desktop.
Save kyoungho-koo/077fafdb45775d1522c5dae194b0adef to your computer and use it in GitHub Desktop.
linked list
struct list_elem
{
struct list_elem *prev;
struct list_elem *next;
};
struct list
{
struct list_elem head;
struct list_elem tail;
};
#define offsetof(TYPE,MEMBER) ((size_t)&((TYPE*)0)->MEMBER)
#define list_entry(LIST_ELEM,STRUCT,MEMBER) \
( (STRUCT*)( (uin8_t*)&(LIST_ELEM)->next - offsetof(STRUCT,MEMBER,next) ) )
#define LIST_INITIALIZER(NAME) { { NULL, &(NAME).tail }, \
{ &(NAME).head, NULL } }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment