О'кей, рассмотрим на простом примере. C++ Builder 6, Console Application, Release-версия.
| Код | #include <conio.h> #include <stdio.h>
int sum(int x, int y) { return x+y; }
int main(int argc, char* argv[]) { int x,y,z; printf("Enter x, y: "); scanf("%d,%d", &x, &y); printf("sum of %d and %d is %d", x, y, sum(x,y)); getch(); return 0; } |
...и-и-и во что это превратилось:
Функция main:
| Код | .text:00401228 ; --------------- S U B R O U T I N E --------------------------------------- .text:00401228 .text:00401228 ; Attributes: bp-based frame .text:00401228 .text:00401228 ; int __cdecl main(int argc,const char **argv,const char *envp) .text:00401228 _main proc near ; DATA XREF: .data:0040E04Co .text:00401228 .text:00401228 var_8 = dword ptr -8 .text:00401228 var_4 = dword ptr -4 .text:00401228 argc = dword ptr 8 .text:00401228 argv = dword ptr 0Ch .text:00401228 envp = dword ptr 10h .text:00401228 .text:00401228 push ebp .text:00401229 mov ebp, esp .text:0040122B add esp, 0FFFFFFF8h .text:0040122E push offset format ; "Enter x, y: " .text:00401233 call _printf .text:00401238 pop ecx .text:00401239 lea eax, [ebp+var_8] .text:0040123C push eax .text:0040123D lea edx, [ebp+var_4] .text:00401240 push edx .text:00401241 push offset aDD ; "%d,%d" .text:00401246 call _scanf .text:0040124B add esp, 0Ch .text:0040124E mov ecx, [ebp+var_8] .text:00401251 push ecx .text:00401252 mov eax, [ebp+var_4] .text:00401255 push eax .text:00401256 call sub_40121C .text:0040125B add esp, 8 .text:0040125E push eax .text:0040125F mov edx, [ebp+var_8] .text:00401262 push edx .text:00401263 mov ecx, [ebp+var_4] .text:00401266 push ecx .text:00401267 push offset aSumOfDAndDIsD ; "sum of %d and %d is %d" .text:0040126C call _printf .text:00401271 add esp, 10h .text:00401274 call _getch .text:00401279 xor eax, eax .text:0040127B pop ecx .text:0040127C pop ecx .text:0040127D pop ebp .text:0040127E retn .text:0040127E _main endp .text:0040127E .text:0040127E ; --------------------------------------------------------------------------- |
Функция sum:
| Код | .text:0040121C ; --------------- S U B R O U T I N E --------------------------------------- .text:0040121C .text:0040121C ; Attributes: bp-based frame .text:0040121C .text:0040121C sub_40121C proc near ; CODE XREF: _main+2Ep .text:0040121C .text:0040121C arg_0 = dword ptr 8 .text:0040121C arg_4 = dword ptr 0Ch .text:0040121C .text:0040121C push ebp .text:0040121D mov ebp, esp .text:0040121F mov eax, [ebp+arg_0] .text:00401222 add eax, [ebp+arg_4] .text:00401225 pop ebp .text:00401226 retn .text:00401226 sub_40121C endp .text:00401226 .text:00401226 ; --------------------------------------------------------------------------- |
Если бы функция sum была inline, то мы получили бы следующее:
| Код | .text:0040121C ; --------------- S U B R O U T I N E --------------------------------------- .text:0040121C .text:0040121C ; Attributes: bp-based frame .text:0040121C .text:0040121C ; int __cdecl main(int argc,const char **argv,const char *envp) .text:0040121C _main proc near ; DATA XREF: .data:0040E04Co .text:0040121C .text:0040121C var_8 = dword ptr -8 .text:0040121C var_4 = dword ptr -4 .text:0040121C argc = dword ptr 8 .text:0040121C argv = dword ptr 0Ch .text:0040121C envp = dword ptr 10h .text:0040121C .text:0040121C push ebp .text:0040121D mov ebp, esp .text:0040121F add esp, 0FFFFFFF8h .text:00401222 push offset format ; "Enter x, y: " .text:00401227 call _printf .text:0040122C pop ecx .text:0040122D lea eax, [ebp+var_8] .text:00401230 push eax .text:00401231 lea edx, [ebp+var_4] .text:00401234 push edx .text:00401235 push offset aDD ; "%d,%d" .text:0040123A call _scanf .text:0040123F add esp, 0Ch .text:00401242 mov ecx, [ebp+var_4] .text:00401245 add ecx, [ebp+var_8] .text:00401248 push ecx .text:00401249 mov eax, [ebp+var_8] .text:0040124C push eax .text:0040124D mov edx, [ebp+var_4] .text:00401250 push edx .text:00401251 push offset aSumOfDAndDIsD ; "sum of %d and %d is %d" .text:00401256 call _printf .text:0040125B add esp, 10h .text:0040125E call _getch .text:00401263 xor eax, eax .text:00401265 pop ecx .text:00401266 pop ecx .text:00401267 pop ebp .text:00401268 retn .text:00401268 _main endp .text:00401268 .text:00401268 ; --------------------------------------------------------------------------- |
Как видно, во втором случае sum не оформлена в виде отдельной функции, а "встроена" в main... |