lkml.org 
[lkml]   [2009]   [Apr]   [16]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [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.

\
 
 \ /
  Last update: 2009-04-16 20:35    [W:0.343 / U:0.508 seconds]
©2003-2014 Jasper Spaans. Advertise on this site