Google
  Web www.spinics.net

Fwd: Question about container_of macro.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]


Hi,

I am sorry for spamming, it really isn't a usb related question, but I
didn't get the answer on kernelnewbies list. I am sure will get it
from here........atleast from Greg :-) since I am referring his
article.


---------- Forwarded message ----------
From: Manish Katiyar <mkatiyar@xxxxxxxxx>
Date: Jan 16, 2008 11:08 PM
Subject: Question about container_of macro.
To: kernelnewbies <kernelnewbies@xxxxxxxxxxxx>


Hi,

It might be a very silly question, but I was going through the
definition and explaination of container_of macro from the below link
http://www.kroah.com/log/linux/container_of.html.

However what i understood is that, given a pointer to one of the
members of a structure, it would return a pointer to the parent
structure.

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) );})


Since even after declaring __mptr as member type we are anyway
typecasting it to char *. I am sure I must be missing something very
silly :-( ...

Thanks in advance.

--
Thanks & Regards,
********************************************
Manish Katiyar  ( http://mkatiyar.googlepages.com )
3rd Floor, Fair Winds Block
EGL Software Park
Off Intermediate Ring Road
Bangalore 560071, India
***********************************************



-- 
Thanks & Regards,
********************************************
Manish Katiyar  ( http://mkatiyar.googlepages.com )
3rd Floor, Fair Winds Block
EGL Software Park
Off Intermediate Ring Road
Bangalore 560071, India
***********************************************

-------------------------------------------------------------------------
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]

  Powered by Linux