How container_of() works?

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

 



235 /**
236 * container_of - cast a member of a structure out to the containing structure
237 *
238 * @ptr: the pointer to the member.
239 * @type: the type of the container struct this is embedded in.
240 * @member: the name of the member within the struct.
241 *
242 */
243 #define container_of( ptr, type, member) ({ \
244 const typeof( (( type *)0)->member ) *__mptr = (ptr); \
245 ( type *)( (char *)__mptr - offsetof(type,member) );})

Can someone please explain how the above macro works and in what situations it is used ? Thanks.

rgds
Arun

[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