Re: Macro explanation

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

 



On Fri, Mar 09, 2012 at 11:51:54PM +0530, Vijay Chauhan wrote:
> Hi,
> 
> I'm checking the container_of and offsetof macro
> 
> #define container_of(ptr, type, member) ({ \
>                 const typeof( ((type *)0)->member ) *__mptr = (ptr);
>                 (type *)( (char *)__mptr - offsetof(type,member) );})
> 
> #define offsetof(TYPE, MEMBER) \
>  ((size_t) &((TYPE *)0)->MEMBER)
> 
> 
> I did not understand the first line of both macro. Will it not create
> the NULL pointer dereference problem? I know it works and read some
> article but it did not explain this part, so can anyone explain why
> the NULL pointer error is not coming. Am I missing something?
> Any C language specification of such example.

Did you see this:
	http://www.kroah.com/log/linux/container_of.html

after reading that, if you have further questions, please let us know.

greg k-h

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@xxxxxxxxxxxxxxxxx
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


[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