zoukankan      html  css  js  c++  java
  • linux内核list操作实例

     1 /**
     2 *teakey
     3 *2012-07-25
     4 */
     5 #include<stdio.h>
     6 #include<stdlib.h>
     7 #define list_entry(ptr,type,member) \
     8  (type *)( (char *)(ptr)  -  (unsigned long)(&(((type*)0)->member)))
     9 
    10 struct list_head
    11 {
    12     struct list_head *next;
    13     struct list_head *prev;
    14 };
    15 typedef struct person
    16 {
    17     int age;
    18     struct list_head list;
    19 }Person;
    20 
    21 int main(int argc,char **argv)
    22 
    23 {
    24     Person person;
    25     person.age=25;
    26     struct list_head list;
    27     list.next=&list;
    28     list.prev=&list;
    29     person.list=list;
    30     Person *pos=list_entry(&person.list,Person,list);
    31     printf("the age of person is %d",pos->age);
    32     return 0;
    33 
    34 }

    上面的例子应该不用讲太多把,相信你自己哦。。。
    关键是linux内核链表的实现,这个很有实际应用价值。list_entry,简直就是太棒了。






  • 相关阅读:
    Andoird注册功能
    android注册功能
    寒假周总结六
    android登录功能
    Android登录功能
    android登录功能
    每日日报2021.1.24
    每日博客2021.1.23
    每日日报2021.1.22
    每日日报2021.1.21
  • 原文地址:https://www.cnblogs.com/iteakey/p/2611348.html
Copyright © 2011-2022 走看看