首页 > 技术文章 > Linux内核之旅 List_entry()

593213556wuyubao 2014-04-24 09:16 原文

#include "iostream"
#define List_entry(type,member)\
(type *)((char*)(&member)-(unsigned long)(&(((type*)0)->data)) )
using namespace std;

struct list_head{
    int data;
    char* name;
};

void main(){
    list_head list;
    cout<<List_entry(struct list_head,list.name)<<endl;

    cout<<&list<<endl;

    cout<<&(((struct list_head *)0)->name)<<endl;
}

 

推荐阅读