Is there any physical part of memory with a NULL address (0)?

I know that there is an old saying when you want to indicate that this particular pointer does not indicate anything, it should be set to NULL (actually 0), but I wonder if there really is a physical part of memory with a NULL address ( 0)?

+3
source share
7 answers

There is always a physical address of 0 (but it may not necessarily be displayed in physical memory), but on a regular platform, any calls are usually performed in a virtual address space (as jweyrich shows below, you can use mmap, etc., to directly display the physical address space ), so any attempt to read / write to address 0 may cause some kind of exception.

In simpler processors (I think, microcontrollers, etc.), this protection cannot be, therefore, if you try to write down address 0, you have nothing to catch.

Note also that a null pointer does not have to point to address 0; the only guarantee is that it will be compared with an integer value 0.

+6

, ( ) 0, .

, /.

+3

, 0. , DOS- - , , , , , , 0. ++ Standard, , undefined , 0 ( CPU/), , , undefined. , , 0, 0 , 0 ..: 0 - , , , , , " ", .

+3

, . , , . , .

+1

NULL . . , , , .

+1

, 0 NULL C/++, , () . ( , , ..) , *(reinterpret_cast<int *>(&my_pointer)) == 0.

Unix ( Linux) , , . . , , Linux Windows.

+1

++, , , " " undefined:

1.9 [intro.execution]

undefined (, ). [: , undefined. ]

..., dynamic_cast , delete , , , " " == 0

4.10 [conv.ptr]

  • The null pointer constant is the integral constant expression (5.19) of the rvalue of an integer type that is zero.
+1
source

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


All Articles