0

Based on what i know, C++ reference doesn't take a memory. Because it is just an alias of a variable that reference is pointing to.

But When I compile the simple code and see the assembly by using lldb, I saw the result like below.

int main()
{
    int a = 10;
    int &refToInt = a;
}

0x100003f90 <+0>: pushq  %rbp
0x100003f91 <+1>: movq   %rsp, %rbp
0x100003f94 <+4>: xorl   %eax, %eax
0x100003f96 <+6>:  movl   $0xa, -0x4(%rbp)
0x100003f9d <+13>: leaq   -0x4(%rbp), %rcx
0x100003fa1 <+17>: movq   %rcx, -0x10(%rbp)

I think the reference is using memory -0x10 isn't it??

I want to know what is happening

Thank you

KimJunseo
  • 73
  • 3

0 Answers0