RE: sys_init_module()

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

 



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

 You seem to have ignored parts of the FAQ that answer your question.
I quote from the answer to question 5.2:

   According to the language definition, a constant 0 in a pointer
   context is converted into a null pointer at compile time.  That
   is, in an initialization, assignment, or comparison when one
   side is a variable or expression of pointer type, the compiler
   can tell that a constant 0 on the other side requests a null
   pointer, and generate the correctly-typed null pointer value.

and from 5.3:

   Substituting the trivial pointer expression "p" for "expr", we
   have
     if(p)	is equivalent to		if(p != 0)

   and this is a comparison context, so the compiler can tell that
   the (implicit) 0 is actually a null pointer constant, and use
   the correct null pointer value.  There is no trickery involved
   here; compilers do work this way, and generate identical code
   for both constructs.  The internal representation of a null
   pointer does *not* matter.

And if that doesn't settle the argument, here is one more:

5.10:	But wouldn't it be better to use NULL (rather than 0), in case
	the value of NULL changes, perhaps on a machine with nonzero
	internal null pointers?

A:	No.  (Using NULL may be preferable, but not for this reason.)
	Although symbolic constants are often used in place of numbers
	because the numbers might change, this is *not* the reason that
	NULL is used in place of 0.  Once again, the language guarantees
	that source-code 0's (in pointer contexts) generate null
	pointers.  NULL is used only as a stylistic convention.  See
	questions 5.5 and 9.2.


 Also, of all the architectures mentioned in the FAQ that use non-zero 
values for null pointers, how many have Linux ports??


-Ravi.

__________________________________________________
Do You Yahoo!?
Yahoo! Games - play chess, backgammon, pool and more
http://games.yahoo.com/
--
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