- 论坛徽章:
- 0
|
引用就是用指针实现的
fun函数用引用,fun1函数用指针,两个函数功能一样。反汇编后,两个函数的汇编代码完全一样。
fun函数:
void fun(int &n)
{
n++;
printf("in fun. n=%d\n",n);
}
fun函数的汇编代码:
4: void fun(int &n)
5: {
00401020 push ebp
00401021 mov ebp,esp
00401023 sub esp,40h
00401026 push ebx
00401027 push esi
00401028 push edi
00401029 lea edi,[ebp-40h]
0040102C mov ecx,10h
00401031 mov eax,0CCCCCCCCh
00401036 rep stos dword ptr [edi]
6: n++;
00401038 mov eax,dword ptr [ebp+8]
0040103B mov ecx,dword ptr [eax]
0040103D add ecx,1
00401040 mov edx,dword ptr [ebp+8]
00401043 mov dword ptr [edx],ecx
7: printf("in fun. n=%d\n",n);
00401045 mov eax,dword ptr [ebp+8]
00401048 mov ecx,dword ptr [eax]
0040104A push ecx
0040104B push offset string "in fun. n=%d\n" (0042201c)
00401050 call printf (004010e0)
00401055 add esp,8
8: }
fun1函数:
void fun1(int *p)
{
(*p)++;
printf("in fun1. *p=%d\n",*p);
}
fun1函数的汇编代码:
9:
10: void fun1(int *p)
11: {
00401070 push ebp
00401071 mov ebp,esp
00401073 sub esp,40h
00401076 push ebx
00401077 push esi
00401078 push edi
00401079 lea edi,[ebp-40h]
0040107C mov ecx,10h
00401081 mov eax,0CCCCCCCCh
00401086 rep stos dword ptr [edi]
12: (*p)++;
00401088 mov eax,dword ptr [ebp+8]
0040108B mov ecx,dword ptr [eax]
0040108D add ecx,1
00401090 mov edx,dword ptr [ebp+8]
00401093 mov dword ptr [edx],ecx
13: printf("in fun1. *p=%d\n",*p);
00401095 mov eax,dword ptr [ebp+8]
00401098 mov ecx,dword ptr [eax]
0040109A push ecx
0040109B push offset string "in fun1. *p=%d\n" (00422fb4)
004010A0 call printf (004010e0)
004010A5 add esp,8
14: } |
|