linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 2.4] Backport of container_of macro
@ 2002-11-12  0:16 Hanna Linder
  0 siblings, 0 replies; only message in thread
From: Hanna Linder @ 2002-11-12  0:16 UTC (permalink / raw)
  To: linux-kernel; +Cc: hannal


This nifty little macro is used a lot in 2.5 but does not exist
in 2.4 yet. Here is a patch to include it.

Hanna

 kernel.h |   11 +++++++++++
 1 files changed, 11 insertions(+)

diff -Nru linux-2.4.20-rc1/include/linux/kernel.h 
linux-container_of/include/linux/kernel.h
--- linux-2.4.20-rc1/include/linux/kernel.h	Mon Nov 11 15:23:09 2002
+++ linux-container_of/include/linux/kernel.h	Mon Nov 11 15:23:16 2002
@@ -174,6 +174,17 @@
 extern void __out_of_line_bug(int line) ATTRIB_NORET;
 #define out_of_line_bug() __out_of_line_bug(__LINE__)

+/*
+ * container_of - cast a member of a structure out to the containing 
structure
+ *
+ * @ptr:        the pointer to the member.
+ * @type:       the type of the container struct this is embedded in.
+ * @member:     the name of the member within the struct.
+ */
+#define container_of(ptr, type, member) ({                      \
+	const typeof( ((type *)0)->member ) *__mptr = (ptr);    \
+	(type *)( (char *)__mptr - offsetof(type,member) );})
+
 #endif /* __KERNEL__ */

 #define SI_LOAD_SHIFT	16


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2002-11-12  0:01 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-11-12  0:16 [PATCH 2.4] Backport of container_of macro Hanna Linder

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).