再问一个问题哈
在main函数中声明static变量是不是没有意义?
在main函数中声明static变量是不是没有意义?
Only the Code Tells the Truth K.I.S.S
#include <stdio.h> #include <stdlib.h> void test(void) { int x; x = 1; printf_s("%d\n", x); } int main(void) { test(); return EXIT_SUCCESS; }
; Listing generated by Microsoft (R) Optimizing Compiler Version 17.00.61030.0 TITLE F:\Projects\Visual Studio 2012\Projects\test\test11\test11.cpp .686P .XMM include listing.inc .model flat INCLUDELIB OLDNAMES PUBLIC ??_C@_03PMGGPEJJ@?$CFd?6?$AA@ ; `string' EXTRN __imp__printf_s:PROC EXTRN @__security_check_cookie@4:PROC ; COMDAT ??_C@_03PMGGPEJJ@?$CFd?6?$AA@ CONST SEGMENT ??_C@_03PMGGPEJJ@?$CFd?6?$AA@ DB '%d', 0aH, 00H ; `string' CONST ENDS PUBLIC _main PUBLIC ?test@@YAXXZ ; test ; Function compile flags: /Ogtp ; File f:\projects\visual studio 2012\projects\test\test11\test11.cpp ; COMDAT ?test@@YAXXZ _TEXT SEGMENT ?test@@YAXXZ PROC ; test, COMDAT ; 6 : int x; ; 7 : x = 1; ; 8 : printf_s("%d\n", x); push 1 push OFFSET ??_C@_03PMGGPEJJ@?$CFd?6?$AA@ call DWORD PTR __imp__printf_s add esp, 8 ; 9 : } ret 0 ?test@@YAXXZ ENDP ; test _TEXT ENDS ; Function compile flags: /Ogtp ; File f:\projects\visual studio 2012\projects\test\test11\test11.cpp ; COMDAT _main _TEXT SEGMENT _main PROC ; COMDAT ; 8 : printf_s("%d\n", x); push 1 push OFFSET ??_C@_03PMGGPEJJ@?$CFd?6?$AA@ call DWORD PTR __imp__printf_s add esp, 8 ; 13 : test(); ; 14 : return EXIT_SUCCESS; xor eax, eax ; 15 : } ret 0 _main ENDP _TEXT ENDS END
#include <stdio.h> #include <stdlib.h> int main(void) { int x; x = 1; printf_s("%d\n", x); return EXIT_SUCCESS; }
; Listing generated by Microsoft (R) Optimizing Compiler Version 17.00.61030.0 TITLE F:\Projects\Visual Studio 2012\Projects\test\test11\test11.cpp .686P .XMM include listing.inc .model flat INCLUDELIB OLDNAMES PUBLIC ??_C@_03PMGGPEJJ@?$CFd?6?$AA@ ; `string' EXTRN __imp__printf_s:PROC EXTRN @__security_check_cookie@4:PROC ; COMDAT ??_C@_03PMGGPEJJ@?$CFd?6?$AA@ CONST SEGMENT ??_C@_03PMGGPEJJ@?$CFd?6?$AA@ DB '%d', 0aH, 00H ; `string' CONST ENDS PUBLIC _main ; Function compile flags: /Ogtp ; File f:\projects\visual studio 2012\projects\test\test11\test11.cpp ; COMDAT _main _TEXT SEGMENT _main PROC ; COMDAT ; 6 : int x; ; 7 : x = 1; ; 8 : printf_s("%d\n", x); push 1 push OFFSET ??_C@_03PMGGPEJJ@?$CFd?6?$AA@ call DWORD PTR __imp__printf_s add esp, 8 ; 9 : return EXIT_SUCCESS; xor eax, eax ; 10 : } ret 0 _main ENDP _TEXT ENDS END
#include <stdio.h> #include <stdlib.h> int main(void) { int x; return EXIT_SUCCESS; }
; Listing generated by Microsoft (R) Optimizing Compiler Version 17.00.61030.0 TITLE F:\Projects\Visual Studio 2012\Projects\test\test11\test11.cpp .686P .XMM include listing.inc .model flat INCLUDELIB OLDNAMES EXTRN @__security_check_cookie@4:PROC PUBLIC _main ; Function compile flags: /Ogtp ; File f:\projects\visual studio 2012\projects\test\test11\test11.cpp ; COMDAT _main _TEXT SEGMENT _main PROC ; COMDAT ; 6 : int x; ; 7 : return EXIT_SUCCESS; xor eax, eax ; 8 : } ret 0 _main ENDP _TEXT ENDS END