From: simon.brand@postadigitale.de (Simon Brand)
To: kernelnewbies@lists.kernelnewbies.org
Subject: container_of
Date: Sat, 17 Jan 2015 17:32:37 +0100 [thread overview]
Message-ID: <20150117173237.69c3e04b@fx> (raw)
Good evening,
i read the article about the container_of function:
http://www.kroah.com/log/linux/container_of.html
I understand what it does and how it works.
I thought, it could be simplified by replacing it through this:
#define container_of(ptr, type, member) ({ \
(type *)( (char *)ptr - offsetof(type,member) );})
Original:
#define container_of(ptr, type, member) ({ \
const typeof( ((type *)0)->member ) *__mptr = (ptr);
(type *)( (char *)__mptr - offsetof(type,member) );})
ptr has the type of a pointer to the member, which should be the same
as __mptr? The value should although be the same.
First I tried it in a self written script, then replaced it in
include/linux/kernel.h and compiled it as usermode linux -> working
well.
Then I compiled it and run it in a VM, but it is not working.
Can you please explain to me, why the original version is always working
and "mine" is not?
Thank you for your time!
Regards,
Simon
next reply other threads:[~2015-01-17 16:32 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-01-17 16:32 Simon Brand [this message]
2015-01-17 16:58 ` container_of Manish Katiyar
2015-01-17 19:45 ` container_of Simon Brand
2015-01-17 19:53 ` container_of Mike Krinkin
2015-01-19 15:18 ` container_of Simon Brand
2015-01-17 19:13 ` container_of Anish Kumar
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=20150117173237.69c3e04b@fx \
--to=simon.brand@postadigitale.de \
--cc=kernelnewbies@lists.kernelnewbies.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 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).