Why is memory address 0x0 reserved and for what?

Why is memory address 0x0 reserved and for what? I am having trouble understanding exactly what, thanks for the help

+5
source share
2 answers

This is basically an agreement, and it is implementation specific.

The C language standard (C99 or C11) and some other programming languages, such as Lisp, have the concept of a null pointer that cannot be dereferenced (this will be undefined behavior , segmentation error ) and differs from any other pointer (in some valid memory location) . Tony Hoar modestly called this concept โ€œthe error of my billion dollarsโ€ , and some languages โ€‹โ€‹(Haskell, Ocaml) have marked unions (for example, 'a option in Ocaml).

Most implementations (but not all) represent a null pointer at address 0.

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

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

In theory (and in the past) addresses can be more complex than numbers ... (in the 1980s, for example, segmentation of x86 memory on i286 and iAPX432 , Rekursiv , etc.)

Read some books and web pages on C programming, microprocessor architectures and instruction sets,, virtual memory , MMU s.

+2
source

It is not common practice in paged memory systems to map the first (zero) page by default. This is a convention typically executed by the linker. When the program loader reads an executable file, it never receives instructions to display the first logical page.

The reason for this is the detection of null pointer errors.

 int *whatever = 0 ; . . . . *whatever = 10 ; 

will result in access violation.

However, as a rule, the process can display the first (zero) page after starting the launch, and in some cases you can specify linker options that allow you to rely on sections of programs.

+1
source

Source: https://habr.com/ru/post/1240413/


All Articles