Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is the memory address 0x0 reserved, and for what?

Why is the memory address 0x0 reserved, and for what? I am having trouble understanding for what exactly, thank you for helping

like image 447
Khalil Khoury Avatar asked Jan 12 '16 08:01

Khalil Khoury


People also ask

What is at address 0x0?

0x0 is actually 0 but in hex. Usually we use 0x0 to check whether the address is not set by us and it is set to default value by the solidity which is 0x0.

Is 0x0 a valid address?

Since the zero page can be mapped and therefore 0x0 is a valid address, the zero bit pattern should not be used for the null pointer.

What does 0x0 mean in C++?

0x0 is just 0 written in hexadecimal notation.

Is 0 a valid memory address?

Memory address 0 is called the null pointer. Your program is never allowed to look at or store anything into memory address 0, so the null pointer is a way of saying "a pointer to nothing". Note that a null pointer is not the same as a null character; do not confuse the two.


1 Answers

It is mostly a convention, and it is implementation specific.

The C language standard (C99 or C11) -and some other programming languages such as Lisp- has the notion of null pointer which cannot be dereferenced (that would be undefined behavior, segmentation fault) and is different of any other pointer (to some valid memory location). Tony Hoare modestly called that notion "my billion dollar mistake", and some languages (Haskell, Ocaml) have some tagged unions types (e.g. 'a option in Ocaml) instead.

Most implementations (but not all) represent the null pointer by address 0.

In practice, on a desktop, laptop or tablet, a user-mode C program runs in some virtual address space where the page containing the address 0 is not mapped. (On some Linux, you perhaps could mmap(2) with MAP_FIXED the address 0, but that would be poor taste...)

In some embedded microcontrollers (e.g. AVR), address 0 could be used.

In theory (and in the past), addresses might be more complex than a number... (in the 1980s, e.g. x86 memory segmentation on i286, and iAPX432 addressing, Rekursiv architecture, etc...)

Read several books and web pages on C programming, microprocessor architectures & instruction sets, operating system principles, virtual memory, MMUs.

like image 68
Basile Starynkevitch Avatar answered Oct 04 '22 13:10

Basile Starynkevitch