What is the difference between r-value references and l-value references? (CodeGen)

What is a reference to an r-value in terms of a lower level. I just can't wrap my head around me! Can I see an example of the generated code (equivalent to C or x86 / x64) from the r-value link compared to the l-value link?

For example, what does this design look like? Do not copy at this time.

vector<SomethingHUUGE> myFunc(); void foo(vector<SomethingHUUGE>&&); int main() { foo(myFunc()); return 0; } 
+3
source share
3 answers

There is no difference for code generation. The only semantic difference between the two is that you know that the RValue link is about to be destroyed, and the lvalue link will not.

+5
source

this can help think of both types of links as high-level concepts. None of them have an obvious low-level implementation. They can be represented by pointers, but often they are simply high-level aliases, and therefore they generally have no low-level representation. No additional code is generated, the link is simply replaced by the object that it refers to.

In cases where the link cannot be completely removed before the code is generated, both the rvalue and the lvalue links are usually represented as pointers as a memory address.

+2
source

The value of r in the expression has no name.

In most cases, this is a temporary object. If you have no way to use it after the expression, then this is the value of r.

0
source

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


All Articles