Feature #2044

Move container_of and ARRAY_SIZE to sys/sysmacros.h

Added by Alexey Zaytsev about 2 years ago. Updated almost 2 years ago.

Status:Resolved Start date:2012-01-30
Priority:Normal Due date:
Assignee:Alexey Zaytsev % Done:

0%

Category:- Spent time: -
Target version:-
Difficulty:Bite-size Tags:needs-triage

Description

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

History

Updated by Alexey Zaytsev about 2 years ago

Q: Do we need to add the FreeBSD copyright/license for such trivial piece of code?

Updated by Rich Lowe about 2 years ago

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.

Updated by Alexey Zaytsev about 2 years ago

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.

Updated by Alexey Zaytsev about 2 years ago

  • Subject changed from Add a container_of macro to Move container_of and ARRAY_SIZE to sys/sysmacros.h

Updated by Alexey Zaytsev almost 2 years ago

  • Status changed from New to Resolved

Also available in: Atom PDF