Skip to content

Instantly share code, notes, and snippets.

@ctlaltlaltc
ctlaltlaltc / list.h
Created April 14, 2015 12:38
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;