[C++基础]011_#define的代码生成的汇编码在哪里
现在有一段源码:
1 #include <iostream> 2 using namespace std; 3 4 #define DefFunc cout<<"Hello, Define function."<<endl;\ 5 cout<<"This is a defined function"<<endl; 6 7 int main(){ 8 DefFunc 9 DefFunc 10 DefFunc 11 system("pause"); 12 return 0; 13 }
如书中所说,通过查看汇编码,我们可以看到宏定义的函数被完全的嵌入进main函数了,如下:
DefFunc 00BA14C6 mov esi,esp 00BA14C8 mov eax,dword ptr [__imp_std::endl (0BAA314h)] 00BA14CD push eax 00BA14CE push offset string "Hello, Define function." (0BA7858h) 00BA14D3 mov ecx,dword ptr [__imp_std::cout (0BAA318h)] 00BA14D9 push ecx 00BA14DA call std::operator<<<std::char_traits<char> > (0BA1145h) 00BA14DF add esp,8 00BA14E2 mov ecx,eax 00BA14E4 call dword ptr [__imp_std::basic_ostream<char,std::char_traits<char> >::operator<< (0BAA300h)] 00BA14EA cmp esi,esp 00BA14EC call @ILT+400(__RTC_CheckEsp) (0BA1195h) 00BA14F1 mov esi,esp 00BA14F3 mov eax,dword ptr [__imp_std::endl (0BAA314h)] 00BA14F8 push eax 00BA14F9 push offset string "This is a defined function" (0BA7838h) 00BA14FE mov ecx,dword ptr [__imp_std::cout (0BAA318h)] 00BA1504 push ecx 00BA1505 call std::operator<<<std::char_traits<char> > (0BA1145h) 00BA150A add esp,8 00BA150D mov ecx,eax 00BA150F call dword ptr [__imp_std::basic_ostream<char,std::char_traits<char> >::operator<< (0BAA300h)] 00BA1515 cmp esi,esp 00BA1517 call @ILT+400(__RTC_CheckEsp) (0BA1195h) DefFunc 00BA151C mov esi,esp 00BA151E mov eax,dword ptr [__imp_std::endl (0BAA314h)] 00BA1523 push eax 00BA1524 push offset string "Hello, Define function." (0BA7858h) 00BA1529 mov ecx,dword ptr [__imp_std::cout (0BAA318h)] 00BA152F push ecx 00BA1530 call std::operator<<<std::char_traits<char> > (0BA1145h) 00BA1535 add esp,8 00BA1538 mov ecx,eax 00BA153A call dword ptr [__imp_std::basic_ostream<char,std::char_traits<char> >::operator<< (0BAA300h)] 00BA1540 cmp esi,esp 00BA1542 call @ILT+400(__RTC_CheckEsp) (0BA1195h) 00BA1547 mov esi,esp 00BA1549 mov eax,dword ptr [__imp_std::endl (0BAA314h)] 00BA154E push eax 00BA154F push offset string "This is a defined function" (0BA7838h) 00BA1554 mov ecx,dword ptr [__imp_std::cout (0BAA318h)] 00BA155A push ecx 00BA155B call std::operator<<<std::char_traits<char> > (0BA1145h) 00BA1560 add esp,8 00BA1563 mov ecx,eax 00BA1565 call dword ptr [__imp_std::basic_ostream<char,std::char_traits<char> >::operator<< (0BAA300h)] 00BA156B cmp esi,esp 00BA156D call @ILT+400(__RTC_CheckEsp) (0BA1195h) DefFunc 00BA1572 mov esi,esp 00BA1574 mov eax,dword ptr [__imp_std::endl (0BAA314h)] 00BA1579 push eax 00BA157A push offset string "Hello, Define function." (0BA7858h) 00BA157F mov ecx,dword ptr [__imp_std::cout (0BAA318h)] 00BA1585 push ecx 00BA1586 call std::operator<<<std::char_traits<char> > (0BA1145h) 00BA158B add esp,8 00BA158E mov ecx,eax 00BA1590 call dword ptr [__imp_std::basic_ostream<char,std::char_traits<char> >::operator<< (0BAA300h)] 00BA1596 cmp esi,esp 00BA1598 call @ILT+400(__RTC_CheckEsp) (0BA1195h) 00BA159D mov esi,esp 00BA159F mov eax,dword ptr [__imp_std::endl (0BAA314h)] 00BA15A4 push eax 00BA15A5 push offset string "This is a defined function" (0BA7838h) 00BA15AA mov ecx,dword ptr [__imp_std::cout (0BAA318h)] 00BA15B0 push ecx 00BA15B1 call std::operator<<<std::char_traits<char> > (0BA1145h) 00BA15B6 add esp,8 00BA15B9 mov ecx,eax 00BA15BB call dword ptr [__imp_std::basic_ostream<char,std::char_traits<char> >::operator<< (0BAA300h)] 00BA15C1 cmp esi,esp 00BA15C3 call @ILT+400(__RTC_CheckEsp) (0BA1195h) system("pause");