Re: inline asm question(s)

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

 



hi

> > to get the offset of member c in this struct, we need to size of all
> > members which come b4 c: offset_of_c = sizeof(a)+sizeof(b) .
> no, this is not correct. the compilers are free to add padding to meet
> alignment requirements of a given platform.

you are correct, maybe i oversimplified a bit.... 

> > however, a more generic and _much_ better way:
> > lets say you had a pointer to a struct foo (foo_ptr), so you can get the
> > offset like this:
> > 
> > offset_of_c = &foo_ptr->c - foo_ptr
> > 
> > the macro actually saves the subtraction, by letting the compiler think
> > that foo_ptr is 0 ((TYPE *)0) (located at start of memory).
> the assumption here is that null is repersented as a bunch of zeros on
> a platform. if that is  not the case, you will get strange results.

i dont see your point. this has nothing to do with the NULL pointer, but 
with a pointer whose base address is 0, which saves the subtraction...
as far as this macro concerns, NULL may be defined like this:
#define NULL ((void *)400)

comments??

-- 
========================================================================
nir.

--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           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