From: Ryan Mallon <rmallon@gmail.com>
To: peter <lifulong2c2i2c@gmail.com>
Cc: linux-kernel@vger.kernel.org
Subject: Re: Question with "container_of(ptr, type, member)"
Date: Wed, 31 Aug 2011 09:14:59 +1000 [thread overview]
Message-ID: <4E5D6EF3.3000908@gmail.com> (raw)
In-Reply-To: <1314701099.1728.6.camel@peter-2ci2c>
On 30/08/11 20:44, peter wrote:
> I have a question about the macro " container_of(ptr, type, member) "
> I can write it as this,
> #define container_of(ptr, type, member) ({ \
> (type *) ((char *) ptr - offset_of(type, member)); \
> })
> It can act the same as
> #define container_of(ptr, type, member) ({ \
> const typeof( ((type *)0)->member ) *__mptr = (ptr); \
> (type *)( (char *)__mptr - offsetof(type,member) );})
> So why we don't use the first one ?
> Thanks for your answer.
> (I am a kernel newbie ,and sorry for my poor english~)
The version used by the Linux kernel does type checking.
~Ryan
next prev parent reply other threads:[~2011-08-30 23:15 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-08-30 10:44 Question with "container_of(ptr, type, member)" peter
2011-08-30 23:14 ` Ryan Mallon [this message]
2011-08-31 0:52 ` peter
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=4E5D6EF3.3000908@gmail.com \
--to=rmallon@gmail.com \
--cc=lifulong2c2i2c@gmail.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox