The null pointer should not really be 0. It is guaranteed in the C standard when the value 0 is specified in the context of the pointer that the compiler processed as NULL .
But the value 0 that you use in your source code is just syntactic sugar that has nothing to do with the actual physical address, the value of the null pointer points to.
For more details see:
- Why is NULL / 0 an illegal memory cell for an object?
- Why is a null pointer used for a null pointer?
An application in your operating system has a unique address space, which it sees as a continuous block of memory (memory is not physically continuous, it is simply an โimpressionโ that the operating system provides to each program).
For the most part, each virtual memory space of a process is exposed in a similar and predictable way (this is the memory layout in a Linux process, 32-bit mode):
(image from Anatomy program in memory )
Look at the text segment (the default base base on x86 is 0x08048000, selected by the default linker script for static binding).
Why is the magic 0x08048000? Probably because Linux borrowed this address from System V i386 ABI.
... and why then did system V use 0x08048000?
The value was chosen to place the stack under the .text section, growing down. 0x48000 bytes can be displayed on a single page table already required by the .text section (thus preserving the page table in most cases), while the remaining 0x08000000 will allow more space for hungry applications.
Is there anything below 0x08048000? There may be nothing (it's only 128M), but you can pretty much display everything you want using the mmap () system call .
See also:
manlio
source share