mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Mikael Pettersson <mikpe@it.uu.se>
To: Schrober <franzschrober@yahoo.de>
Cc: linux-kernel@vger.kernel.org
Subject: Re: container-of Implementation
Date: Mon, 14 Jan 2013 13:22:11 +0100	[thread overview]
Message-ID: <20723.63603.114080.51605@pilspetsen.it.uu.se> (raw)
In-Reply-To: <1635127.Ytukyo95FQ@bentobox>

Schrober writes:
 > Hi,
 > 
 > I wondered why the container_of implementation is so complicated.
 > 
 > #define container_of(ptr, type, member) ({			\
 > 	const typeof( ((type *)0)->member ) *__mptr = (ptr);	\
 > 	(type *)( (char *)__mptr - offsetof(type,member) );})
 > 
 > isn't the __mptr not unnecessary? Why not following version?
 > 
 > #define container_of(ptr, type, member) \
 >     ((type *)((char *)(ptr) - offsetof(type, member)))

Compile-time type checking.  The first version requires ptr to be
assignment-compatible with the type of the struct member, the second
version accepts random junk for ptr.

  reply	other threads:[~2013-01-14 12:23 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-01-14 10:46 Schrober
2013-01-14 12:22 ` Mikael Pettersson [this message]
2013-01-14 12:23 ` Geert Uytterhoeven

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=20723.63603.114080.51605@pilspetsen.it.uu.se \
    --to=mikpe@it.uu.se \
    --cc=franzschrober@yahoo.de \
    --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

all inboxes | Powered by JetHome®