Are C ++ references guaranteed to use pointers "internally"?

Looking at the links in C ++, I noticed that in all the implementations I was looking at, an internal pointer was used.

Does the C ++ standard guarantee that the link will use the pointer inside, or would it be nice if the implementation used a more "efficient" solution? (Currently, I don’t see how this could be done β€œbetter” because when a new stack stack is created, there really is no bulletproof way to easily find out which offset from the pointer on the stack refers to the variable it refers to, because the stack is pretty dynamic)

Note. I understand the difference between a pointer and a link in C ++ (this question has nothing to do with this)

+5
source share
3 answers

If you mean that the link requires the compiler to allocate storage for the pointer, then this is not indicated.

& section; 8.3.2 / 4

It is not indicated whether a storage link is needed.

EDIT: To record Martin Bonner's comment as a useful, practical note,

[F] or for debugging purposes, it can be very helpful to know what is happening "under the hood." (For example, to answer questions such as "why is it not completely removed from the rails?"). In practice, compilers implement links as pointers (if they cannot fully optimize the link).

+10
source

No, it makes no guarantees as to how the links are applied. C ++ defines the semantics of links, not their implementation.

+4
source

The standard does not indicate how this link is executed, how it works.

It also says nothing about stack frames, which is another implementation detail.

+4
source

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


All Articles