内核代码中一些c语言用法
2021-05-06 07:29
标签:compiler 执行 virt ptr 翻译 comm drive 语言 csdn 内核中的定义: Cscope tag: container_of scripts/kconfig/list.h 分析详见: http://www.cnblogs.com/cute/archive/2011/04/01/2002474.html 内容如下: 执行: REF: gcc 编译 GCC 参数详解 [翻译]15个最常用的GCC编译器参数 GCC编译优化指南 GCC编译C语言程序完整演示 GCC编译器30分钟入门教程 内核代码中一些c语言用法 标签:compiler 执行 virt ptr 翻译 comm drive 语言 csdn 原文地址:https://www.cnblogs.com/shaohef/p/3930380.htmlcontainer_of,(C 语言 up cast)
# line filename / context / line
1 27 drivers/gpu/drm/radeon/mkregtable.c >
#define container_of(ptr, type, member) ({ \
2 63 drivers/staging/lustre/include/linux/libcfs/libcfs.h >
#define container_of(ptr, type, member) \
3 78 drivers/staging/rtl8192e/rtllib.h >
#define container_of(ptr, type, member) ({ \
4 61 drivers/staging/rtl8192u/ieee80211/ieee80211.h >
#define container_of(ptr, type, member) ({ \
5 791 include/linux/kernel.h >
#define container_of(ptr, type, member) ({ \
6 18 scripts/kconfig/list.h >
#define container_of(ptr, type, member) ({ \
7 26 tools/perf/util/include/linux/kernel.h >
#define container_of(ptr, type, member) ({ \
8 84 tools/virtio/linux/kernel.h >
#define container_of(ptr, type, member) ({ \ 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) );})
结构体和数据
谈结构体struct 初始化多出的点号“.”,数组[]初始化多出的逗号“,”
cat test.c
1 #include
gcc test.c -o test
./test