All of lore.kernel.org
 help / color / mirror / Atom feed
From: Hanna Linder <hannal@us.ibm.com>
To: linux-kernel@vger.kernel.org
Cc: hannal@us.ibm.com
Subject: [PATCH 2.4] Backport of container_of macro
Date: Mon, 11 Nov 2002 16:16:11 -0800	[thread overview]
Message-ID: <14650000.1037060171@w-hlinder> (raw)


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


                 reply	other threads:[~2002-11-12  0:01 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=14650000.1037060171@w-hlinder \
    --to=hannal@us.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.