Embedded Linux development - container_of explored

Three Realms 2022-08-06 07:40:34 阅读数:900


First step

insert image description here

Step 2

insert image description here

Step 3 The real container_of

Learn optimization tips from kernel developers:

#define container_of(ptr, type, member) ({ \ const typeof( ((type *)0)->member ) *__mptr = (ptr); \(type *)( (char *)__mptr - offsetof(type,member) );})

If there is a problem with the parameters entered by the developer when using it: ptr does not match the type of member, there will be warnings when compiling, but if the line change is removed, there will be no such thing.

版权声明:本文为[Three Realms]所创,转载请带上原文链接,感谢。 https://javamana.com/2022/218/202208060629430439.html