- 论坛徽章:
- 0
|
本帖最后由 jwj070524 于 2014-08-29 13:29 编辑
- #include <stdio.h>
- int main ()
- {
- int const v = 0;
- int *ptr = const_cast<int*>(&v);
- *ptr = 1;
- printf("v = %d, *ptr = %d\n", v, *ptr);
- }
复制代码 转换成汇编后:- main:
- .LFB2:
- leal 4(%esp), %ecx
- .LCFI0:
- andl $-16, %esp
- pushl -4(%ecx)
- .LCFI1:
- pushl %ebp
- .LCFI2:
- movl %esp, %ebp ; v => [ebp-12]
- .LCFI3: ; ptr => [ebp-8]
- pushl %ecx
- .LCFI4:
- subl $36, %esp
- .LCFI5:
- movl $0, -12(%ebp) ; [ebp-12] := 0 ;int const v = 0;
- leal -12(%ebp), %eax ; eax := ebp-12 ;eax = &v
- movl %eax, -8(%ebp) ; [ebp-8] := ebp-12 ;ptr = &v
- movl -8(%ebp), %eax ; eax := [ebp-8] ;eax = v
- movl $1, (%eax) ; eax := 1 ;eax = 1
- movl -8(%ebp), %eax ; eax := [ebp-8] ;eax = &v
- movl (%eax), %eax ; eax := [[ebp-8]] ;eax = v
- movl %eax, 8(%esp) ; [esp+8] := [[ebp-8]] ;store (*ptr)
- movl $0, 4(%esp) ; [esp+4] := 0 ;store (v) == 0 由于v是常量,直接赋0
- movl $.LC0, (%esp) ; [esp] := ;store (char const *)
- call printf
复制代码 |
|