RE: sys_init_module()

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

 



On Thu, 25 Apr 2002, Neeraj wrote:

> So, what would be your inference in the case of architectures where the null
> pointer is not designated by 0(zero) (lot of them are mentioned there on the
> C-faq page). What would then ((struct a *)0L)->field refer to and how will the
> compiler know that (null-pointer)->field is required to evaluate the offset of
> field in the structure "a" ?
>
> Any suggestions or hints are welcome. :)

I'm guessing that a compiler would see that it's an offset from 0, and
hence know that something 8 bytes from the start of the struct returns an
8.

However, I'll admit that I may be wrong, and I don't have an architecture
that I could test this on.  In these cases (where I don't really know for
sure) I always use some safe code:

(void *)&((struct a*)0L)->field - (void *)(struct a*)0L

which is similar to what you suggested in an earlier post.

Note that before the (void*) cast, the first expression (the address of
"field") is a pointer to the type of "field", while the second is to
something of type struct.  You cast to (unsigned long) to compare them,
but I prefer to use pointer arithmetic (subtracting 2 pointers of the
same type is perfectly legal, and since the addressed objects are
different I use (void*)).

Regards,
Paul Gearon

Software Engineer                Telephone:   +61 7 3876 2188
Plugged In Software              Fax:         +61 7 3876 4899
http://www.PIsoftware.com        PGP Key available via finger

Catapultam habeo. Nisi pecuniam omnem mihi dabis, ad caput tuum saxum
immane mittam.
(Translation from latin: "I have a catapult. Give me all the money,
or I will fling an enormous rock at your head.")




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