From: peter <lifulong2c2i2c@gmail.com>
To: Ryan Mallon <rmallon@gmail.com>
Cc: linux-kernel@vger.kernel.org
Subject: Re: Question with "container_of(ptr, type, member)"
Date: Wed, 31 Aug 2011 08:52:20 +0800 [thread overview]
Message-ID: <1314751940.1593.2.camel@peter-2ci2c> (raw)
In-Reply-To: <4E5D6EF3.3000908@gmail.com>
I see now, It can gives an waring: "warning: initialization from
incompatible pointer type", when give it an wrong type.
thanks for your answer!
On Wed, 2011-08-31 at 09:14 +1000, Ryan Mallon wrote:
> 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
>
prev parent reply other threads:[~2011-08-31 0:52 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
2011-08-31 0:52 ` peter [this message]
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=1314751940.1593.2.camel@peter-2ci2c \
--to=lifulong2c2i2c@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=rmallon@gmail.com \
/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