container_of宏剖析//该宏位于include/linux/kernel.h 1.定义格式 /** * container_of - cast a member of a structure out to the containing structure * * @ptr: the pointer to the member. * @type: the type of the container struct this is embedded in. * @member:the nam
宏的定义在程序中是非常有用的,但是使用不当,就会给自身造成很大的困扰.通常这种困扰为:宏使用在计算方面. 本例子主要是在宏的计算方面,很多时候,大家都知道定义一个计算的宏,对于编译和编程是多么的有用.现在定义有以下一个计算 "乘法" 的宏. #include <stdio.h> #define MUL(a) ((a)*(a)*(a)) int main(int argc,char *argv[]) { int i = 10; int sum = MUL(i); printf