C++:Type
Objects, references, functions including function template specializations, and expressions have a property called type, which both restricts the operations that are permitted for those entities and provides semantic meaning to the otherwise generic sequences of bits.
Reference type
Assembly result
레퍼런스 타입이 실제로 어떻게 작동하는지 확인하고 싶을 경우 아래와 같은 코드를 사용한다.
objdump를 사용하여 asm코드를 확인하면 아래와 같다.
_main:
0: 55 pushq %rbp
1: 48 89 e5 movq %rsp, %rbp
4: 31 c0 xorl %eax, %eax
6: 48 8d 4d f8 leaq -8(%rbp), %rcx
a: c7 45 fc 00 00 00 00 movl $0, -4(%rbp)
11: c7 45 f8 0b 00 00 00 movl $11, -8(%rbp)
18: 48 89 4d f0 movq %rcx, -16(%rbp)
1c: 48 89 4d e8 movq %rcx, -24(%rbp)
20: 5d popq %rbp
21: c3 retq
포인터 타입인 18
번 째 라인과, 레퍼런스 타입인 1c
번 째 라인이 동일한 것으로 보아, 실제 어셈블리 코드에서는 Reference와 Pointer는 동일하게 동작하는 것을 알 수 있다.