D
D
DjTolib2021-07-22 20:15:22
C++ / C#
DjTolib, 2021-07-22 20:15:22

Where is nullptr stored? Is it different for different programs?

Where is nullptr stored? Is it different for different programs? question from social security)

Answer the question

In order to leave comments, you need to log in

5 answer(s)
M
Mercury13, 2021-07-22
@DjTolib

What does "stored" mean?
• The nullptr value is stored in a pointer variable, just like any &someObject.
• There is no object of the correct “objective” form (if, of course, the object has some kind of invariant or at least a table of virtual methods) at the address *nullptr; on most operating systems, dereferencing nullptr results in a segmentation violation and an instant crash (but not necessarily - for example, DOS).
• In all ABIs I know of (x86/DOS, x86 and x64/Windows, x86 and x64/Linux), nullptr equals address zero. This is justified - this address is usually where the interrupt table, entry point, prefix segment or other system crap is located, you definitely shouldn't meddle here. But theoretically it is not necessary. This address, of course, is common for ABI, so that it is possible to combine the results of compilation in different languages ​​into one program.

D
Denis Zagaevsky, 2021-07-22
@zagayevskiy

nullptr is just a keyword denoting a null pointer. Since it is empty, it is not stored anywhere.
Is it different in different programs... Is 0 different in different programs?

L
longclaps, 2021-07-22
@longclaps

Come down here .
Hit something like

int* f()
{
  return nullptr;
}

Look at the output in assembler.
Play around with compilers.
Profit.

D
Developer, 2021-07-22
@samodum

...ptr is a pointer. Pointer to what? If you read books, you would know what to address.
Therefore nullptr is different

R
res2001, 2021-07-23
@res2001

nullptr is itself a constant (now its real value is not important). Where is stored, for example, 2 or 100500?
Here's when you make the assignment: Then ptr will store nullptr. If you look at the assembler code of such an assignment, then there will be something like: In this example, I believe that the value of nullptr is 0. Here you can see that nullptr is stored directly in the code and is one of the operands of the mov assembly instruction. About what is stored in memory, where nullptr points (and ptr from the example), wrote Mercury13
void *ptr = nullptr;
mov ax, 0;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question