|
发表于 2019-6-16 18:15:56
|
显示全部楼层
- #include <iostream>
- int main(void)
- {
- const int number = 1234;
- *const_cast<int *>(&number) = 100;
- std::cout << *const_cast<int *>(&number) << std::endl;
- return 0;
- }
复制代码
- main:
- .LFB1494:
- .file 1 "main.cpp"
- .loc 1 4 0
- .cfi_startproc
- pushq %rbp
- .seh_pushreg %rbp
- .cfi_def_cfa_offset 16
- .cfi_offset 6, -16
- movq %rsp, %rbp
- .seh_setframe %rbp, 0
- .cfi_def_cfa_register 6
- subq $48, %rsp
- .seh_stackalloc 48
- .seh_endprologue
- .loc 1 4 0
- call __main
- .LVL0:
- .loc 1 5 0
- movl $1234, -4(%rbp)
- .loc 1 6 0
- leaq -4(%rbp), %rax
- movl $100, (%rax)
- .loc 1 7 0
- leaq -4(%rbp), %rax # 这里访问number变量
- movl (%rax), %eax
- movl %eax, %edx
- movq .refptr._ZSt4cout(%rip), %rcx
- call _ZNSolsEi
- movq .refptr._ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_(%rip), %rdx
- movq %rax, %rcx
- call _ZNSolsEPFRSoS_E
- .loc 1 8 0
- movl $0, %eax
- .loc 1 9 0
- addq $48, %rsp
- popq %rbp
- .cfi_restore 6
- .cfi_def_cfa 7, 8
- ret
复制代码 |
|