Fwd: Question about container_of macro.
"Manish Katiyar" <[email protected]> Thu, 17 Jan 2008 23:38:09 +0530
| Newsgroups | gmane.linux.usb.devel |
|---|---|
| Message-ID | <[email protected]> |
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 <[email protected]> Date: Jan 16, 2008 11:08 PM Subject: Question about container_of macro. To: kernelnewbies <[email protected]> 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/ _______________________________________________ [email protected] To unsubscribe, use the last form field at: https://lists.sourceforge.net/lists/listinfo/linux-usb-devel