Move container_of and ARRAY_SIZE to sys/sysmacros.h
|Assignee:||Alexey Zaytsev||% Done:|
The code can be taken from FreeBSD:
#define container_of(p, stype, field) \
((stype *)(((uint8_t *)(p)) - offsetof(stype, field)))
If you wonder what it is, here's an explanation of the Linux container_of macro, which is similar: http://www.kroah.com/log/linux/container_of.html
Q: Do we need to add the FreeBSD copyright/license for such trivial piece of code?
There's an implementation in the IB code, here: usr/src/uts/common/sys/ib/clients/rdsv3/rdsv3_impl.h#123
You could take this one, or add one, but when you do please clean this one up.
I don't want a repeat of offsetof's miriad definitions.
Thanks! No idea, how I've missed it.
I'll just move it to sysmacros.h. And I guess I'll take ARRAY_SIZE along with it, if there are no objections.
- Subject changed from Add a container_of macro to Move container_of and ARRAY_SIZE to sys/sysmacros.h
- Status changed from New to Resolved
Also available in: Atom