Re: Fwd: Question about container_of macro. | |
| [Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] | |
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/
_______________________________________________
linux-usb-devel@xxxxxxxxxxxxxxxxxxxxx
To unsubscribe, use the last form field at:
https://lists.sourceforge.net/lists/listinfo/linux-usb-devel
[Home] [Video for Linux] [Photo] [Yosemite Forum] [Yosemite Photos] [Video Projectors] [PDAs] [Hacking TiVo] [Linux Kernel] [Linux SCSI] [XFree86] [Devices] [Big List of Linux Books] [Free Dating]
![]() |