Linux 核心巨集 container of

2021-08-16 07:18:53 字數 814 閱讀 7205

container_of(ptr, type, member);

arguments

ptrthe pointer to the member.//代表指標

type

the type

ofthe

container

struct

this

isembedded

in.//型別

member

//成員變數

the name of the member within the struct.

作用:通過乙個結構體變數中的成員位址找到這個結構體變數的首位址

#include 

#undef offsetof

#ifdef __compiler_offsetof

#define offsetof(type, member) __compiler_offsetof(type, member)

#else

#define offsetof(type, member) ((size_t)&((type *)0)->member)

#endif

#define container_of(ptr, type, member) ()

typedef

struct student;

intmain

()結果:

ss:0x7fff156fe320

temp:0x7fff156fe320

通過s.num的位址找到了結構體變數的位址

linux核心中ffs x 巨集

linux核心中ffs x 巨集是平台相關的巨集,在arm平台,該巨集定義在 arch arm include asm bitops.h define ffs x static inline int fls int x t t 等於找到 t 第乙個為1的位 從低位開始 並把該位保留為1其餘位清0.例...

linux 核心 THIS MODULE巨集定義詳解

結構體struct module在核心中代表乙個核心模組,通過insmod 實際執行init module系統呼叫 把自己編寫的核心模組插入核心時,模組便與乙個 struct module結構體相關聯,並成為核心的一部分。下面是結構體struct module的完整定義,接下來會逐個解釋 struc...

linux 核心模組中的巨集

author dansen xzd2734 163.com 編寫模組時一般都需要包含標頭檔案,而在module.h中定義了符號 module kernel version static const char module kernel version attribute section modinf...