Re: Fwd: Question about container_of macro.
Laurent Pinchart <[email protected]> Fri, 18 Jan 2008 01:01:54 +0100
| Newsgroups | gmane.linux.usb.devel |
|---|---|
| Message-ID | <[email protected]> |
On Thursday 17 January 2008, Alan Stern wrote:
> On Thu, 17 Jan 2008, Manish Katiyar wrote:
> > My question is instead of defining container_of as:
> >
> > #define container_of(ptr, type, member) ({ \
> > const typeof( ((type *)0)->member ) *__mptr = (ptr);
> > (type *)( (char *)__mptr - offsetof(type,member) );})
> >
> >
> > Why won't this simply work :
> >
> > #define container_of(ptr, type, member) ({ \
> > (type *)( (char *)(ptr) - offsetof(type,member)
> > );})
>
> Indeed, or even this:
>
> #define container_of(ptr, type, member) \
> ((type *) ((char *)(ptr) - offsetof(type,member)))
If I'm not mistaken, that's because
const typeof( ((type *)0)->member ) *__mptr = (ptr);
will warn (or maybe even bail out ?) if ptr is not a pointer to a variable of
member's type.
Laurent Pinchart
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
[email protected]
To unsubscribe, use the last form field at:
https://lists.sourceforge.net/lists/listinfo/linux-usb-devel