标签:compiler 执行 virt ptr 翻译 comm drive 语言 csdn
内核中的定义:
Cscope tag: container_of
# line filename / context / line
1 27 drivers/gpu/drm/radeon/mkregtable.c <<container_of>>
#define container_of(ptr, type, member) ({ \
2 63 drivers/staging/lustre/include/linux/libcfs/libcfs.h <<container_of>>
#define container_of(ptr, type, member) \
3 78 drivers/staging/rtl8192e/rtllib.h <<container_of>>
#define container_of(ptr, type, member) ({ \
4 61 drivers/staging/rtl8192u/ieee80211/ieee80211.h <<container_of>>
#define container_of(ptr, type, member) ({ \
5 791 include/linux/kernel.h <<container_of>>
#define container_of(ptr, type, member) ({ \
6 18 scripts/kconfig/list.h <<container_of>>
#define container_of(ptr, type, member) ({ \
7 26 tools/perf/util/include/linux/kernel.h <<container_of>>
#define container_of(ptr, type, member) ({ \
8 84 tools/virtio/linux/kernel.h <<container_of>>
#define container_of(ptr, type, member) ({ \
scripts/kconfig/list.h
1 #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER) 2 3 /** 4 * container_of - cast a member of a structure out to the containing structure 5 * @ptr: the pointer to the member. 6 * @type: the type of the container struct this is embedded in. 7 * @member: the name of the member within the struct. 8 * 9 */ 10 #define container_of(ptr, type, member) ({ 11 const typeof( ((type *)0)->member ) *__mptr = (ptr); 12 (type *)( (char *)__mptr - offsetof(type,member) );})
分析详见:
http://www.cnblogs.com/cute/archive/2011/04/01/2002474.html
cat test.c
内容如下:
1 #include <stdio.h> 2 3 #define MAXTITL 30 4 #define MAXAUTL 20 5 6 struct book { 7 float off; 8 char title[MAXTITL]; 9 char author[MAXAUTL]; 10 float value; 11 12 }; 13 14 int main() 15 { 16 puts("C lange test!"); 17 struct book b1 = { .value = 19.9, .author = "author", .title="C test tutorial" }; 18 printf("Book value: %f\n", b1.value); 19 printf("Book author: %s\n", b1.author); 20 printf("Book title: %s\n", b1.title); 21 printf("Book off: %f\n", b1.off); 22 int m,n; 23 int a2[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 0}; 24 for(n=0;n<11;n++) 25 printf("%d\n",a2[n]); 26 int a1[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 0, }; 27 for(m=0;m<11;m++) 28 printf("%d\n",a1[m]); 29 return 0; 30 }
执行:
gcc test.c -o test ./test
REF:
标签:compiler 执行 virt ptr 翻译 comm drive 语言 csdn
原文地址:https://www.cnblogs.com/shaohef/p/3930380.html