Question about container_of macro.

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

 



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

--
To unsubscribe from this list: send an email with
"unsubscribe kernelnewbies" to ecartis@xxxxxxxxxxxx
Please read the FAQ at http://kernelnewbies.org/FAQ


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux