Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
在 libc/glibc 中可能无法接受 container_of() 是否有技术原因?
谢谢,陈兹
有无数的宏和函数不在 C 库中——它们中的任何一个都不存在不需要有任何理由,而且 Linux 内核的 container_of 宏的实用性有限。但是,我认为没有任何技术原因无法在 stdlib.h 中将其定义为
#define container_of(ptr, type, member) (type*)((char*)(ptr) - offsetof(type, member))