Feature #2044

Move container_of and ARRAY_SIZE to sys/sysmacros.h

Added by Alexey Zaytsev over 3 years ago. Updated almost 3 years ago.

Status:ResolvedStart date:2012-01-30
Priority:NormalDue date:
Assignee:Alexey Zaytsev% Done:

0%

Category:-
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

#1 Updated by Alexey Zaytsev over 3 years ago

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

#2 Updated by Rich Lowe over 3 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.

#3 Updated by Alexey Zaytsev over 3 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.

#4 Updated by Alexey Zaytsev over 3 years ago

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

#5 Updated by Alexey Zaytsev almost 3 years ago

  • Status changed from New to Resolved

Also available in: Atom