[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20090416183327.GC26366@ZenIV.linux.org.uk>
Date: Thu, 16 Apr 2009 19:33:27 +0100
From: Al Viro <viro@...IV.linux.org.uk>
To: H Hartley Sweeten <hartleys@...ionengravers.com>
Cc: Vegard Nossum <vegard.nossum@...il.com>,
linux-kernel@...r.kernel.org
Subject: Re: [PATCH] block/genhd.c: fix sparse warning
On Thu, Apr 16, 2009 at 02:03:39PM -0400, H Hartley Sweeten wrote:
> Maybe something like:
>
> #define container_of(ptr, type, member) ({ \
> const typeof( ((type *)0)->member ) *__m_##ptr = (ptr); \
> (type *)( (char *)__m_##ptr - offsetof(type,member) );})
>
> I don't know if that actually works. ;-)
_Think_ of it. Will do bleeding wonders if you say
container_of(f(), struct foo, bar)
won't it?
No, the real solution for that is this:
#define container_of(ptr, type, member) (type *) \
((char *)(1 ? (ptr) : ((const typeof(((type *)0)->member) *)(ptr))) \
- offsetof(type, member))
Same amount of typechecking, no local variables, no ({ }) uses.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists