Skip to content

Instantly share code, notes, and snippets.

@timcsy
timcsy / list.h
Created January 16, 2018 02:41 — forked from ctlaltlaltc/list.h
Simple doubly linked list implementation, modify from linux kernel list.h, so we can use it in application.
#ifndef _LIST_H
#define _LIST_H
#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
#define container_of(ptr, type, member) ({ \
const typeof( ((type *)0)->member ) *__mptr = (ptr); \
(type *)( (char *)__mptr - offsetof(type,member) );})
struct list_head {
struct list_head *next, *prev;