这是编译器编译后的汇编代码:
; Listing generated by Microsoft (R) Optimizing Compiler Version 17.00.61030.0
TITLE C:\Users\TonyD_000\documents\visual studio 2012\Projects\test01\test2\main.cpp
.686P
.XMM
include listing.inc
.model flat
INCLUDELIB MSVCRTD
INCLUDELIB OLDNAMES
PUBLIC ?fun@@YAXH@Z ; fun
PUBLIC _main
PUBLIC ??_C@_03DPLIHHLN@?$CFd?0?$AA@ ; `string'
EXTRN __imp__printf:PROC
EXTRN __imp___getch:PROC
EXTRN __RTC_CheckEsp:PROC
EXTRN __RTC_InitBase:PROC
EXTRN __RTC_Shutdown:PROC
; COMDAT rtc$TMZ
rtc$TMZ SEGMENT
__RTC_Shutdown.rtc$TMZ DD FLAT:__RTC_Shutdown
rtc$TMZ ENDS
; COMDAT rtc$IMZ
rtc$IMZ SEGMENT
__RTC_InitBase.rtc$IMZ DD FLAT:__RTC_InitBase
rtc$IMZ ENDS
; COMDAT ??_C@_03DPLIHHLN@?$CFd?0?$AA@
CONST SEGMENT
??_C@_03DPLIHHLN@?$CFd?0?$AA@ DB '%d,', 00H ; `string'
CONST ENDS
; Function compile flags: /Odtp /RTCsu /ZI
; File c:\users\tonyd_000\documents\visual studio 2012\projects\test01\test2\main.cpp
; COMDAT _main
_TEXT SEGMENT
_i$ = -8 ; size = 4
_main PROC ; COMDAT
; 10 : {
push ebp
mov ebp, esp
sub esp, 204 ; 000000ccH
push ebx
push esi
push edi
lea edi, DWORD PTR [ebp-204]
mov ecx, 51 ; 00000033H
mov eax, -858993460 ; ccccccccH
rep stosd
; 11 : int i=5;
mov DWORD PTR _i$[ebp], 5
; 12 : fun(i);
mov eax, DWORD PTR _i$[ebp]
push eax
call ?fun@@YAXH@Z ; fun
add esp, 4
; 13 : fun;
; 14 :
; 15 : _getch();
mov esi, esp
call DWORD PTR __imp___getch
cmp esi, esp
call __RTC_CheckEsp
; 16 : }
xor eax, eax
pop edi
pop esi
pop ebx
add esp, 204 ; 000000ccH
cmp ebp, esp
call __RTC_CheckEsp
mov esp, ebp
pop ebp
ret 0
_main ENDP
_TEXT ENDS
; Function compile flags: /Odtp /RTCsu /ZI
; File c:\users\tonyd_000\documents\visual studio 2012\projects\test01\test2\main.cpp
; COMDAT ?fun@@YAXH@Z
_TEXT SEGMENT
_i$ = 8 ; size = 4
?fun@@YAXH@Z PROC ; fun, COMDAT
; 5 : {
push ebp
mov ebp, esp
sub esp, 192 ; 000000c0H
push ebx
push esi
push edi
lea edi, DWORD PTR [ebp-192]
mov ecx, 48 ; 00000030H
mov eax, -858993460 ; ccccccccH
rep stosd
; 6 : printf("%d,",i);
mov esi, esp
mov eax, DWORD PTR _i$[ebp]
push eax
push OFFSET ??_C@_03DPLIHHLN@?$CFd?0?$AA@
call DWORD PTR __imp__printf
add esp, 8
cmp esi, esp
call __RTC_CheckEsp
; 7 : }
pop edi
pop esi
pop ebx
add esp, 192 ; 000000c0H
cmp ebp, esp
call __RTC_CheckEsp
mov esp, ebp
pop ebp
ret 0
?fun@@YAXH@Z ENDP ; fun
_TEXT ENDS
END
可以看到源代码13、14、15行编译的结果,13行被直接忽略掉了。这是特定编译器的编译结果,对所有警告信息,如何处理,编译器有自由裁量权。你那公司用这种问题考你,根本就没有唯一答案,你反问他想要什么答案、谁会写出这种代码、是否他的公司以写这种代码为能事?
[ 本帖最后由 TonyDeng 于 2014-9-5 12:26 编辑 ]
; Listing generated by Microsoft (R) Optimizing Compiler Version 17.00.61030.0
TITLE C:\Users\TonyD_000\documents\visual studio 2012\Projects\test01\test2\main.cpp
.686P
.XMM
include listing.inc
.model flat
INCLUDELIB MSVCRTD
INCLUDELIB OLDNAMES
PUBLIC ?fun@@YAXH@Z ; fun
PUBLIC _main
PUBLIC ??_C@_03DPLIHHLN@?$CFd?0?$AA@ ; `string'
EXTRN __imp__printf:PROC
EXTRN __imp___getch:PROC
EXTRN __RTC_CheckEsp:PROC
EXTRN __RTC_InitBase:PROC
EXTRN __RTC_Shutdown:PROC
; COMDAT rtc$TMZ
rtc$TMZ SEGMENT
__RTC_Shutdown.rtc$TMZ DD FLAT:__RTC_Shutdown
rtc$TMZ ENDS
; COMDAT rtc$IMZ
rtc$IMZ SEGMENT
__RTC_InitBase.rtc$IMZ DD FLAT:__RTC_InitBase
rtc$IMZ ENDS
; COMDAT ??_C@_03DPLIHHLN@?$CFd?0?$AA@
CONST SEGMENT
??_C@_03DPLIHHLN@?$CFd?0?$AA@ DB '%d,', 00H ; `string'
CONST ENDS
; Function compile flags: /Odtp /RTCsu /ZI
; File c:\users\tonyd_000\documents\visual studio 2012\projects\test01\test2\main.cpp
; COMDAT _main
_TEXT SEGMENT
_i$ = -8 ; size = 4
_main PROC ; COMDAT
; 10 : {
push ebp
mov ebp, esp
sub esp, 204 ; 000000ccH
push ebx
push esi
push edi
lea edi, DWORD PTR [ebp-204]
mov ecx, 51 ; 00000033H
mov eax, -858993460 ; ccccccccH
rep stosd
; 11 : int i=5;
mov DWORD PTR _i$[ebp], 5
; 12 : fun(i);
mov eax, DWORD PTR _i$[ebp]
push eax
call ?fun@@YAXH@Z ; fun
add esp, 4
; 13 : fun;
; 14 :
; 15 : _getch();
mov esi, esp
call DWORD PTR __imp___getch
cmp esi, esp
call __RTC_CheckEsp
; 16 : }
xor eax, eax
pop edi
pop esi
pop ebx
add esp, 204 ; 000000ccH
cmp ebp, esp
call __RTC_CheckEsp
mov esp, ebp
pop ebp
ret 0
_main ENDP
_TEXT ENDS
; Function compile flags: /Odtp /RTCsu /ZI
; File c:\users\tonyd_000\documents\visual studio 2012\projects\test01\test2\main.cpp
; COMDAT ?fun@@YAXH@Z
_TEXT SEGMENT
_i$ = 8 ; size = 4
?fun@@YAXH@Z PROC ; fun, COMDAT
; 5 : {
push ebp
mov ebp, esp
sub esp, 192 ; 000000c0H
push ebx
push esi
push edi
lea edi, DWORD PTR [ebp-192]
mov ecx, 48 ; 00000030H
mov eax, -858993460 ; ccccccccH
rep stosd
; 6 : printf("%d,",i);
mov esi, esp
mov eax, DWORD PTR _i$[ebp]
push eax
push OFFSET ??_C@_03DPLIHHLN@?$CFd?0?$AA@
call DWORD PTR __imp__printf
add esp, 8
cmp esi, esp
call __RTC_CheckEsp
; 7 : }
pop edi
pop esi
pop ebx
add esp, 192 ; 000000c0H
cmp ebp, esp
call __RTC_CheckEsp
mov esp, ebp
pop ebp
ret 0
?fun@@YAXH@Z ENDP ; fun
_TEXT ENDS
END
可以看到源代码13、14、15行编译的结果,13行被直接忽略掉了。这是特定编译器的编译结果,对所有警告信息,如何处理,编译器有自由裁量权。你那公司用这种问题考你,根本就没有唯一答案,你反问他想要什么答案、谁会写出这种代码、是否他的公司以写这种代码为能事?
[ 本帖最后由 TonyDeng 于 2014-9-5 12:26 编辑 ]
授人以渔,不授人以鱼。