Re: NULL dereference ? why not ?

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

 



On Wed, 2007-01-03 at 12:22 +0200, Ramagudi Naziir wrote:
[....]
> I want to ask why NULL dereference is never valid.

Because a NULL pointer is per definitionem "undefined". It actually has
no real value and - looking at the bits in the pointer - there is no
guarantee anywhere that they are all "0". The "NULL" in the C source
file is translated to some hardware defined bitmap. And it makes no
difference that "NULL" is usually #define'd to "(void *)0" - a plain int
"0" is also OK since it is automatically promoted to a pointer with the
value "0" which then translated to the architecture-defined bitmap (you
could have any bitmap value there if you want though there are 2
equivalent simple representations - all "0" and all "1" - which can
easily/efficiently be checked in hardware).

> Why isn't it possible that an application will have some data at
> virtual address zero ?

Practical:
-) Because the NULL pointer on most architectures are there
-) Because there is no real need to have data there - put it on some
other 
    address - it is virtual anyway.
-) Because there is no guarantee that there is the address 0 actually
there.

> is it platform-specific issue or is it by-design in linux ?

It is defined by C in the above way.

	Bernd
-- 
Firmix Software GmbH                   http://www.firmix.at/
mobil: +43 664 4416156                 fax: +43 1 7890849-55
          Embedded Linux Development and Services


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