07-24-2023, 12:06 PM
> **Possible Duplicate:**
> [What is the difference between r-value references and l-value references? (CodeGen)](
<!-- End of automatically inserted text -->
I was wondering, can anyone explain what R-Value references are on a technical level? By that I mean: What happens on assembler level when R-Value references are created.
For a small test to see what happens inside I wrote the following code:
char c = 255;
char &c2 = c;
char &c3 = std::move©;
I know it makes no sense to create a R-Value reference to 'c', but just for the sake of testing I did it anyway, to see what it does. And here's 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©;
lea eax,[c]
push eax
call std::move<unsigned char &> (0ED1235h)
add esp,4
mov dword ptr [c3],eax
I am by far no asm expert but it looks to me that, in this case, 'c3' is a regular reference to 'c' in the end.
If I bind the R-Value reference directly to a temporary (char &&c3 = 255), the last bit of 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 looks of this change, I assume that c3 still actually is a reference to some memory location which holds the value 255. So it's a regular reference - the value is not copied/assigned to c3. Is this true?
Can anyone say if my assumptions are correct or if I am totally off the track? Until now I always thought of R-Value references to match a functions/methods signature (possibly a move-ctor) when it comes to calling resolution, so that the coder knows how to treat the data that is provided (for a move-ctor that would be moving the data instead of copying it).
To defend this rather stupid attempt I just presented: I don't intend to screw around with my code on asm level, I just want to unterstand what technical differences R-Value references introduced compared to the rest that has been around all these years.
Any insights and explanations are more than welcome!
Thanks!
> [What is the difference between r-value references and l-value references? (CodeGen)](
[To see links please register here]
)<!-- End of automatically inserted text -->
I was wondering, can anyone explain what R-Value references are on a technical level? By that I mean: What happens on assembler level when R-Value references are created.
For a small test to see what happens inside I wrote the following code:
char c = 255;
char &c2 = c;
char &c3 = std::move©;
I know it makes no sense to create a R-Value reference to 'c', but just for the sake of testing I did it anyway, to see what it does. And here's 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©;
lea eax,[c]
push eax
call std::move<unsigned char &> (0ED1235h)
add esp,4
mov dword ptr [c3],eax
I am by far no asm expert but it looks to me that, in this case, 'c3' is a regular reference to 'c' in the end.
If I bind the R-Value reference directly to a temporary (char &&c3 = 255), the last bit of 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 looks of this change, I assume that c3 still actually is a reference to some memory location which holds the value 255. So it's a regular reference - the value is not copied/assigned to c3. Is this true?
Can anyone say if my assumptions are correct or if I am totally off the track? Until now I always thought of R-Value references to match a functions/methods signature (possibly a move-ctor) when it comes to calling resolution, so that the coder knows how to treat the data that is provided (for a move-ctor that would be moving the data instead of copying it).
To defend this rather stupid attempt I just presented: I don't intend to screw around with my code on asm level, I just want to unterstand what technical differences R-Value references introduced compared to the rest that has been around all these years.
Any insights and explanations are more than welcome!
Thanks!