Possible duplicate:
What is the difference between r-value links and l-value links? (CodeGen)
I was wondering, can someone explain which R-Value links are at a technical level? By this I mean: what happens at the assembler level when R-Value references are created.
For a little test, to write what is going on inside, I wrote the following code:
char c = 255; char &c2 = c; char &c3 = std::move(c);
I know that it makes no sense to create an R-value reference for 'c', but just for the sake of testing, I did it anyway to see what it was doing. And here is the result:
unsigned char c = 255; mov byte ptr [c],0FFh unsigned char &c2 = c; lea eax,[c] mov dword ptr [c2],eax unsigned char &&c3 = std::move(c); lea eax,[c] push eax call std::move<unsigned char &> (0ED1235h) add esp,4 mov dword ptr [c3],eax
I am certainly an expert on asm, but it seems to me that in this case "c3" is a regular reference to "c" at the end.
If I bind the R-Value link directly to a temporary one (char & c3 = 255), the last bit of the assembler changes as such:
unsigned char &&c3 = 255; mov byte ptr [ebp-29h],0FFh lea eax,[ebp-29h] mov dword ptr [c3],eax
From the views of this change, I assume that c3 is still a reference to some memory location that contains a value of 255. Thus, this is a regular reference - the value is not copied / not assigned to c3. It's true?
Can anyone tell if my assumptions are correct or if I am completely not up to date? Until now, I always thought of R-Value references to match the signature of the functions / methods (maybe move-ctor) when it comes to resolving the call, so the encoder knows how to process the data provided (for moving-ctor which will move data, not copy it).
To protect this rather dumb attempt that I just presented: I'm not going to hang with my code at the asm level, I just want to figure out what technical differences have been made to R-Value compared to the others that have been around all these years.
Any ideas and explanations are more than welcome!
Thanks!