能力值:
( LV2,RANK:10 )
|
-
-
2 楼
答案是什么都不会输出,因为foo函数里的return 0语句并不会被执行,所以被编译器删掉了,然后next就提前了一行,变成了 Next GOTO NEXT;成为了死循环,所下面的printf语句就怎么样都不会被执行了~~
|
能力值:
( LV2,RANK:10 )
|
-
-
3 楼
看汇编
debug
TITLE C:\VCPP32\d\d.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
$$SYMBOLS SEGMENT BYTE USE32 'DEBSYM'
$$SYMBOLS ENDS
$$TYPES SEGMENT BYTE USE32 'DEBTYP'
$$TYPES ENDS
_TLS SEGMENT DWORD USE32 PUBLIC 'TLS'
_TLS ENDS
; COMDAT ??_C@_0O@FEEI@Hello?5World?$CB?6?$AA@
CONST SEGMENT DWORD USE32 PUBLIC 'CONST'
CONST ENDS
; COMDAT ?foo@@YAHXZ
_TEXT SEGMENT PARA USE32 PUBLIC 'CODE'
_TEXT ENDS
; COMDAT _main
_TEXT SEGMENT PARA USE32 PUBLIC 'CODE'
_TEXT ENDS
FLAT GROUP _DATA, CONST, _BSS
ASSUME CS: FLAT, DS: FLAT, SS: FLAT
endif
PUBLIC ?foo@@YAHXZ ; foo
; COMDAT ?foo@@YAHXZ
_TEXT SEGMENT
?foo@@YAHXZ PROC NEAR ; foo, COMDAT
; File C:\VCPP32\d\d.cpp
; Line 7
push ebp
mov ebp, esp
sub esp, 64 ; 00000040H
push ebx
push esi
push edi
lea edi, DWORD PTR [ebp-64]
mov ecx, 16 ; 00000010H
mov eax, -858993460 ; ccccccccH
rep stosd
$NEXT$528:
; Line 12
jmp SHORT $NEXT$528
?foo@@YAHXZ ENDP ; foo
_TEXT ENDS
PUBLIC _main
PUBLIC ??_C@_0O@FEEI@Hello?5World?$CB?6?$AA@ ; `string'
EXTRN _printf:NEAR
EXTRN __chkesp:NEAR
; COMDAT ??_C@_0O@FEEI@Hello?5World?$CB?6?$AA@
; File C:\VCPP32\d\d.cpp
CONST SEGMENT
??_C@_0O@FEEI@Hello?5World?$CB?6?$AA@ DB 'Hello World!', 0aH, 00H ; `string'
CONST ENDS
; COMDAT _main
_TEXT SEGMENT
_n$ = -4
_main PROC NEAR ; COMDAT
; File C:\VCPP32\d\d.cpp
; Line 14
push ebp
mov ebp, esp
sub esp, 68 ; 00000044H
push ebx
push esi
push edi
lea edi, DWORD PTR [ebp-68]
mov ecx, 17 ; 00000011H
mov eax, -858993460 ; ccccccccH
rep stosd
; Line 15
mov DWORD PTR _n$[ebp], 0
; Line 16
call ?foo@@YAHXZ ; foo
; Line 17
push OFFSET FLAT:??_C@_0O@FEEI@Hello?5World?$CB?6?$AA@ ; `string'
call _printf
add esp, 4
; Line 18
xor eax, eax
; Line 19
pop edi
pop esi
pop ebx
add esp, 68 ; 00000044H
cmp ebp, esp
call __chkesp
mov esp, ebp
pop ebp
ret 0
_main ENDP
_TEXT ENDS
END
release
TITLE C:\VCPP32\d\d.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 ??_C@_0O@FEEI@Hello?5World?$CB?6?$AA@
_DATA SEGMENT DWORD USE32 PUBLIC 'DATA'
_DATA ENDS
; COMDAT ?foo@@YAHXZ
_TEXT SEGMENT PARA USE32 PUBLIC 'CODE'
_TEXT ENDS
; COMDAT _main
_TEXT SEGMENT PARA USE32 PUBLIC 'CODE'
_TEXT ENDS
FLAT GROUP _DATA, CONST, _BSS
ASSUME CS: FLAT, DS: FLAT, SS: FLAT
endif
PUBLIC ?foo@@YAHXZ ; foo
; COMDAT ?foo@@YAHXZ
_TEXT SEGMENT
?foo@@YAHXZ PROC NEAR ; foo, COMDAT
; File C:\VCPP32\d\d.cpp
; Line 7
$NEXT$528:
; Line 12
jmp SHORT $NEXT$528
?foo@@YAHXZ ENDP ; foo
_TEXT ENDS
PUBLIC _main
PUBLIC ??_C@_0O@FEEI@Hello?5World?$CB?6?$AA@ ; `string'
EXTRN _printf:NEAR
; COMDAT ??_C@_0O@FEEI@Hello?5World?$CB?6?$AA@
; File C:\VCPP32\d\d.cpp
_DATA SEGMENT
??_C@_0O@FEEI@Hello?5World?$CB?6?$AA@ DB 'Hello World!', 0aH, 00H ; `string'
_DATA ENDS
; COMDAT _main
_TEXT SEGMENT
_main PROC NEAR ; COMDAT
; File C:\VCPP32\d\d.cpp
; Line 16
call ?foo@@YAHXZ ; foo
; Line 17
push OFFSET FLAT:??_C@_0O@FEEI@Hello?5World?$CB?6?$AA@ ; `string'
call _printf
add esp, 4
; Line 18
xor eax, eax
; Line 19
ret 0
_main ENDP
_TEXT ENDS
END
|
能力值:
( LV3,RANK:20 )
|
-
-
4 楼
为什么提前一行就跑到goto next 前面去了?
|
能力值:
( LV2,RANK:10 )
|
-
-
5 楼
这就是BUG所在。
|
能力值:
( LV9,RANK:180 )
|
-
-
6 楼
这不是bug,是编译器优化,你用debug编译试试。
|
能力值:
( LV5,RANK:60 )
|
-
-
7 楼
楼主加油~~
|