首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

为啥小弟我在VC2008.Release下反汇编switch代码,会跳出2个_main的入口函数

2012-03-19 
为啥我在VC2008.Release下反汇编switch代码,会跳出2个_main的入口函数?C/C++ codeint _tmain(int argc, _T

为啥我在VC2008.Release下反汇编switch代码,会跳出2个_main的入口函数?

C/C++ code
int _tmain(int argc, _TCHAR* argv[]){00401000  push        ebp  00401001  mov         ebp,esp 00401003  and         esp,0FFFFFFF8h     int i;    cin>>i;00401006  mov         ecx,dword ptr [__imp_std::cin (402044h)] 0040100C  sub         esp,8 0040100F  lea         eax,[esp+4] 00401013  push        eax  00401014  call        dword ptr [__imp_std::basic_istream<char,std::char_traits<char> >::operator>> (402064h)]     switch (i)0040101A  mov         eax,dword ptr [esp+4] 0040101E  sub         eax,1 00401021  je          wmain+58h (401058h) 00401023  sub         eax,1 00401026  je          wmain+43h (401043h) 00401028  sub         eax,8 0040102B  jne         wmain+7Bh (40107Bh) int _tmain(int argc, _TCHAR* argv[]){    int i;    cin>>i;    switch (i)    {    case 1:        cout<<"1"<<endl;        break;    case 2:        cout<<"2"<<endl;        break;    case 10:        cout<<"10"<<endl;0040102D  mov         ecx,dword ptr [__imp_std::endl (402038h)] 00401033  mov         edx,dword ptr [__imp_std::cout (402048h)] 00401039  push        ecx  0040103A  push        ecx  0040103B  push        offset string "10" (40213Ch) 00401040  push        edx          break;00401041  jmp         wmain+6Bh (40106Bh) private:};int _tmain(int argc, _TCHAR* argv[]){    int i;    cin>>i;    switch (i)    {    case 1:        cout<<"1"<<endl;        break;    case 2:        cout<<"2"<<endl;00401043  mov         eax,dword ptr [__imp_std::endl (402038h)] 00401048  push        eax  00401049  push        ecx  0040104A  mov         ecx,dword ptr [__imp_std::cout (402048h)] 00401050  push        offset string "2" (402138h) 00401055  push        ecx          break;00401056  jmp         wmain+6Bh (40106Bh)     {    case 1:        cout<<"1"<<endl;00401058  mov         edx,dword ptr [__imp_std::endl (402038h)] 0040105E  mov         eax,dword ptr [__imp_std::cout (402048h)] 00401063  push        edx  00401064  push        ecx  00401065  push        offset string "1" (402134h) 0040106A  push        eax  0040106B  call        std::operator<<<std::char_traits<char> > (401220h) 00401070  add         esp,0Ch 00401073  mov         ecx,eax 00401075  call        dword ptr [__imp_std::basic_ostream<char,std::char_traits<char> >::operator<< (402040h)]     default:        break;    }    if( 1==i )0040107B  mov         eax,dword ptr [esp+4] 0040107F  cmp         eax,1 00401082  jne         wmain+9Ah (40109Ah)     {        cout<<"1"<<endl;00401084  mov         ecx,dword ptr [__imp_std::endl (402038h)] 0040108A  mov         edx,dword ptr [__imp_std::cout (402048h)] 00401090  push        ecx  00401091  push        ecx  00401092  push        offset string "1" (402134h) 00401097  push        edx  00401098  jmp         wmain+0CCh (4010CCh)     }    else if( 2==i )0040109A  cmp         eax,2 0040109D  jne         wmain+0B4h (4010B4h)     {        cout<<"2"<<endl;0040109F  mov         eax,dword ptr [__imp_std::endl (402038h)] 004010A4  push        eax  004010A5  push        ecx  004010A6  mov         ecx,dword ptr [__imp_std::cout (402048h)] 004010AC  push        offset string "2" (402138h) 004010B1  push        ecx  004010B2  jmp         wmain+0CCh (4010CCh)     }    else if( 10==i )004010B4  cmp         eax,0Ah 004010B7  jne         wmain+0DCh (4010DCh)     {        cout<<"10"<<endl;004010B9  mov         edx,dword ptr [__imp_std::endl (402038h)] 004010BF  mov         eax,dword ptr [__imp_std::cout (402048h)] 004010C4  push        edx  004010C5  push        ecx  004010C6  push        offset string "10" (40213Ch) 004010CB  push        eax  004010CC  call        std::operator<<<std::char_traits<char> > (401220h) 004010D1  add         esp,0Ch 004010D4  mov         ecx,eax 004010D6  call        dword ptr [__imp_std::basic_ostream<char,std::char_traits<char> >::operator<< (402040h)]     }    return 0;004010DC  xor         eax,eax } 



C/C++ code
//这里是原C++代码int _tmain(int argc, _TCHAR* argv[]){    int i;    cin>>i;    switch (i)    {    case 1:        cout<<"1"<<endl;        break;    case 2:        cout<<"2"<<endl;        break;    case 10:        cout<<"10"<<endl;        break;    default:        break;    }    if( 1==i )    {        cout<<"1"<<endl;    }    else if( 2==i )    {        cout<<"2"<<endl;    }    else if( 10==i )    {        cout<<"10"<<endl;    }    return 0;}


另:在DEBUG模式下就没有。加了switch就会这样

[解决办法]

热点排行