64,671
社区成员
发帖
与我相关
我的任务
分享
struct _test
{
int n;
int m;
int j;
};
int test1(_test * n);
int test2(_test & n);
void main()
{
_test t;
test1(&t);
test2(t);
}
int test1(_test * n)
{
n->j = 10;
n->m = 20;
n->n = 30;
return 0;
}
int test2(_test & n)
{
n.j = 10;
n.m = 20;
n.n = 30;
return 0;
}
然后看看,他们的编译后对应的汇编代码,在vc中编译的时候用/FAs选项输出,用release模式
TITLE G:\test\test\main.cpp
.386P
include listing.inc
if @Version gt 510
.model FLAT
else
_TEXT SEGMENT PARA USE32 PUBLIC 'CODE'
_TEXT ENDS
_DATA SEGMENT DWORD USE32 PUBLIC 'DATA'
_DATA ENDS
CONST SEGMENT DWORD USE32 PUBLIC 'CONST'
CONST ENDS
_BSS SEGMENT DWORD USE32 PUBLIC 'BSS'
_BSS ENDS
_TLS SEGMENT DWORD USE32 PUBLIC 'TLS'
_TLS ENDS
; COMDAT _main
_TEXT SEGMENT PARA USE32 PUBLIC 'CODE'
_TEXT ENDS
; COMDAT ?test1@@YAHPAU_test@@@Z
_TEXT SEGMENT PARA USE32 PUBLIC 'CODE'
_TEXT ENDS
; COMDAT ?test2@@YAHAAU_test@@@Z
_TEXT SEGMENT PARA USE32 PUBLIC 'CODE'
_TEXT ENDS
FLAT GROUP _DATA, CONST, _BSS
ASSUME CS: FLAT, DS: FLAT, SS: FLAT
endif
PUBLIC ?test1@@YAHPAU_test@@@Z ; test1
PUBLIC ?test2@@YAHAAU_test@@@Z ; test2
PUBLIC _main
; COMDAT _main
_TEXT SEGMENT
_t$ = -12
_main PROC NEAR ; COMDAT
; File G:\test\test\main.cpp
; Line 12
00000 83 ec 0c sub esp, 12 ; 0000000cH
; Line 14
00003 8d 44 24 00 lea eax, DWORD PTR _t$[esp+12]
00007 50 push eax
00008 e8 00 00 00 00 call ?test1@@YAHPAU_test@@@Z ; test1
; Line 15
0000d 8d 4c 24 04 lea ecx, DWORD PTR _t$[esp+16]
00011 51 push ecx
00012 e8 00 00 00 00 call ?test2@@YAHAAU_test@@@Z ; test2
; Line 16
00017 83 c4 14 add esp, 20 ; 00000014H
0001a c3 ret 0
_main ENDP
_TEXT ENDS
; COMDAT ?test1@@YAHPAU_test@@@Z
_TEXT SEGMENT
_n$ = 8
?test1@@YAHPAU_test@@@Z PROC NEAR ; test1, COMDAT
; Line 20
00000 8b 44 24 04 mov eax, DWORD PTR _n$[esp-4]
00004 c7 40 08 0a 00
00 00 mov DWORD PTR [eax+8], 10 ; 0000000aH
; Line 21
0000b c7 40 04 14 00
00 00 mov DWORD PTR [eax+4], 20 ; 00000014H
; Line 22
00012 c7 00 1e 00 00
00 mov DWORD PTR [eax], 30 ; 0000001eH
; Line 24
00018 33 c0 xor eax, eax
; Line 25
0001a c3 ret 0
?test1@@YAHPAU_test@@@Z ENDP ; test1
_TEXT ENDS
; COMDAT ?test2@@YAHAAU_test@@@Z
_TEXT SEGMENT
_n$ = 8
?test2@@YAHAAU_test@@@Z PROC NEAR ; test2, COMDAT
; Line 28
00000 8b 44 24 04 mov eax, DWORD PTR _n$[esp-4]
00004 c7 40 08 0a 00
00 00 mov DWORD PTR [eax+8], 10 ; 0000000aH
; Line 29
0000b c7 40 04 14 00
00 00 mov DWORD PTR [eax+4], 20 ; 00000014H
; Line 30
00012 c7 00 1e 00 00
00 mov DWORD PTR [eax], 30 ; 0000001eH
; Line 32
00018 33 c0 xor eax, eax
; Line 33
0001a c3 ret 0
?test2@@YAHAAU_test@@@Z ENDP ; test2
_TEXT ENDS
END
结果就是:他妈的就是一回事。没有谁比谁快