473,216 Members | 2,069 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,216 software developers and data experts.

Difference between Inline function and Ordinary function

Hi,

This is the program that i made to test the usage of inline
function. I am using vc 6.0 compiler. Please see the below program.

int NonInline( int a, int b )
{
return ( a b )? a: b;
}

inline int InLineFun( int a, int b )
{
return ( a b )? a: b;
}

int main(int argc, char* argv[])
{
int a=10,b=20;
NonInline( a,b );
InLineFun( a,b );
return 0;
}

When i compile this source code with vc6.0 compiler i can get the
following code,

; Listing generated by Microsoft (R) Optimizing Compiler Version
12.00.9044.0

TITLE D:\Personal Data\VC Studies\AssembleAnalyze\AssembleAnalyze.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 ?NonInline@@YAHHH@Z
_TEXT SEGMENT PARA USE32 PUBLIC 'CODE'
_TEXT ENDS
; COMDAT ?InLineFun@@YAHHH@Z
_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

INCLUDELIB LIBCD
INCLUDELIB OLDNAMES

PUBLIC ?NonInline@@YAHHH@Z ; NonInline
; Function compile flags: /Odt /GZ /ZI
; File D:\Personal Data\VC Studies\AssembleAnalyze\AssembleAnalyze.cpp
; COMDAT ?NonInline@@YAHHH@Z
_TEXT SEGMENT
_a$ = 8
_b$ = 12
?NonInline@@YAHHH@Z PROC NEAR ; NonInline, COMDAT

; 7 : {

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

; 8 : return ( a b )? a: b;

mov eax, DWORD PTR _a$[ebp]
cmp eax, DWORD PTR _b$[ebp]
jle SHORT $L546
mov ecx, DWORD PTR _a$[ebp]
mov DWORD PTR -68+[ebp], ecx
jmp SHORT $L547
$L546:
mov edx, DWORD PTR _b$[ebp]
mov DWORD PTR -68+[ebp], edx
$L547:
mov eax, DWORD PTR -68+[ebp]

; 9 : }

pop edi
pop esi
pop ebx
mov esp, ebp
pop ebp
ret 0
?NonInline@@YAHHH@Z ENDP ; NonInline
_TEXT ENDS
PUBLIC ?InLineFun@@YAHHH@Z ; InLineFun
PUBLIC _main
EXTRN __chkesp:NEAR
; Function compile flags: /Odt /GZ /ZI
; COMDAT _main
_TEXT SEGMENT
_a$ = -4
_b$ = -8
_main PROC NEAR ; COMDAT

; 17 : {

push ebp
mov ebp, esp
sub esp, 72 ; 00000048H
push ebx
push esi
push edi
lea edi, DWORD PTR [ebp-72]
mov ecx, 18 ; 00000012H
mov eax, -858993460 ; ccccccccH
rep stosd

; 18 : int a=10,b=20;

mov DWORD PTR _a$[ebp], 10 ; 0000000aH
mov DWORD PTR _b$[ebp], 20 ; 00000014H

; 19 : NonInline( a,b );

mov eax, DWORD PTR _b$[ebp]
push eax
mov ecx, DWORD PTR _a$[ebp]
push ecx
call ?NonInline@@YAHHH@Z ; NonInline
add esp, 8

; 20 : InLineFun( a,b );

mov eax, DWORD PTR _b$[ebp]
push eax
mov ecx, DWORD PTR _a$[ebp]
push ecx
call ?InLineFun@@YAHHH@Z ; InLineFun
add esp, 8

; 21 : return 0;

xor eax, eax

; 22 : }

pop edi
pop esi
pop ebx
add esp, 72 ; 00000048H
cmp ebp, esp
call __chkesp
mov esp, ebp
pop ebp
ret 0
_main ENDP
; Function compile flags: /Odt /GZ /ZI
_TEXT ENDS
; COMDAT ?InLineFun@@YAHHH@Z
_TEXT SEGMENT
_a$ = 8
_b$ = 12
?InLineFun@@YAHHH@Z PROC NEAR ; InLineFun, COMDAT

; 12 : {

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

; 13 : return ( a b )? a: b;

mov eax, DWORD PTR _a$[ebp]
cmp eax, DWORD PTR _b$[ebp]
jle SHORT $L553
mov ecx, DWORD PTR _a$[ebp]
mov DWORD PTR -68+[ebp], ecx
jmp SHORT $L554
$L553:
mov edx, DWORD PTR _b$[ebp]
mov DWORD PTR -68+[ebp], edx
$L554:
mov eax, DWORD PTR -68+[ebp]

; 14 : }

pop edi
pop esi
pop ebx
mov esp, ebp
pop ebp
ret 0
?InLineFun@@YAHHH@Z ENDP ; InLineFun
_TEXT ENDS
END

And my doubt is there is no difference in the calling of the inline
function and the non inline function. Why is it so? Wont inline
function's code get replaced inside the calling function?

Thanks,
Amal P.

Sep 7 '06 #1
2 3816
I am sorry. I found my mistake. The problem was there is compiler
option to set. Or else you have make release build in vc6.0


Amal P wrote:
Hi,

This is the program that i made to test the usage of inline
function. I am using vc 6.0 compiler. Please see the below program.

int NonInline( int a, int b )
{
return ( a b )? a: b;
}

inline int InLineFun( int a, int b )
{
return ( a b )? a: b;
}

int main(int argc, char* argv[])
{
int a=10,b=20;
NonInline( a,b );
InLineFun( a,b );
return 0;
}

When i compile this source code with vc6.0 compiler i can get the
following code,

; Listing generated by Microsoft (R) Optimizing Compiler Version
12.00.9044.0

TITLE D:\Personal Data\VC Studies\AssembleAnalyze\AssembleAnalyze.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 ?NonInline@@YAHHH@Z
_TEXT SEGMENT PARA USE32 PUBLIC 'CODE'
_TEXT ENDS
; COMDAT ?InLineFun@@YAHHH@Z
_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

INCLUDELIB LIBCD
INCLUDELIB OLDNAMES

PUBLIC ?NonInline@@YAHHH@Z ; NonInline
; Function compile flags: /Odt /GZ /ZI
; File D:\Personal Data\VC Studies\AssembleAnalyze\AssembleAnalyze.cpp
; COMDAT ?NonInline@@YAHHH@Z
_TEXT SEGMENT
_a$ = 8
_b$ = 12
?NonInline@@YAHHH@Z PROC NEAR ; NonInline, COMDAT

; 7 : {

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

; 8 : return ( a b )? a: b;

mov eax, DWORD PTR _a$[ebp]
cmp eax, DWORD PTR _b$[ebp]
jle SHORT $L546
mov ecx, DWORD PTR _a$[ebp]
mov DWORD PTR -68+[ebp], ecx
jmp SHORT $L547
$L546:
mov edx, DWORD PTR _b$[ebp]
mov DWORD PTR -68+[ebp], edx
$L547:
mov eax, DWORD PTR -68+[ebp]

; 9 : }

pop edi
pop esi
pop ebx
mov esp, ebp
pop ebp
ret 0
?NonInline@@YAHHH@Z ENDP ; NonInline
_TEXT ENDS
PUBLIC ?InLineFun@@YAHHH@Z ; InLineFun
PUBLIC _main
EXTRN __chkesp:NEAR
; Function compile flags: /Odt /GZ /ZI
; COMDAT _main
_TEXT SEGMENT
_a$ = -4
_b$ = -8
_main PROC NEAR ; COMDAT

; 17 : {

push ebp
mov ebp, esp
sub esp, 72 ; 00000048H
push ebx
push esi
push edi
lea edi, DWORD PTR [ebp-72]
mov ecx, 18 ; 00000012H
mov eax, -858993460 ; ccccccccH
rep stosd

; 18 : int a=10,b=20;

mov DWORD PTR _a$[ebp], 10 ; 0000000aH
mov DWORD PTR _b$[ebp], 20 ; 00000014H

; 19 : NonInline( a,b );

mov eax, DWORD PTR _b$[ebp]
push eax
mov ecx, DWORD PTR _a$[ebp]
push ecx
call ?NonInline@@YAHHH@Z ; NonInline
add esp, 8

; 20 : InLineFun( a,b );

mov eax, DWORD PTR _b$[ebp]
push eax
mov ecx, DWORD PTR _a$[ebp]
push ecx
call ?InLineFun@@YAHHH@Z ; InLineFun
add esp, 8

; 21 : return 0;

xor eax, eax

; 22 : }

pop edi
pop esi
pop ebx
add esp, 72 ; 00000048H
cmp ebp, esp
call __chkesp
mov esp, ebp
pop ebp
ret 0
_main ENDP
; Function compile flags: /Odt /GZ /ZI
_TEXT ENDS
; COMDAT ?InLineFun@@YAHHH@Z
_TEXT SEGMENT
_a$ = 8
_b$ = 12
?InLineFun@@YAHHH@Z PROC NEAR ; InLineFun, COMDAT

; 12 : {

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

; 13 : return ( a b )? a: b;

mov eax, DWORD PTR _a$[ebp]
cmp eax, DWORD PTR _b$[ebp]
jle SHORT $L553
mov ecx, DWORD PTR _a$[ebp]
mov DWORD PTR -68+[ebp], ecx
jmp SHORT $L554
$L553:
mov edx, DWORD PTR _b$[ebp]
mov DWORD PTR -68+[ebp], edx
$L554:
mov eax, DWORD PTR -68+[ebp]

; 14 : }

pop edi
pop esi
pop ebx
mov esp, ebp
pop ebp
ret 0
?InLineFun@@YAHHH@Z ENDP ; InLineFun
_TEXT ENDS
END

And my doubt is there is no difference in the calling of the inline
function and the non inline function. Why is it so? Wont inline
function's code get replaced inside the calling function?

Thanks,
Amal P.
Sep 7 '06 #2
Amal P wrote:
Hi,

This is the program that i made to test the usage of inline
function. I am using vc 6.0 compiler. Please see the below program.

int NonInline( int a, int b )
{
return ( a b )? a: b;
}

inline int InLineFun( int a, int b )
{
return ( a b )? a: b;
}
No real difference there. Since these are the only two definitions, it
doesn't
matter, but you could define InLineFun again in another Translation
Unit.
Now, "inline" is also a suggestion to the compiler that the function
call
overhead may exceed the work done in the function, but a good compiler
can figure that out anyway. All functions are visible tot he compiler.

Usually, the inline keyword is (should be) used only after profiling
shows
that the compiler misjudged the call overhead versus work done ratio.

HTH,
Michiel Salters

Sep 8 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

47
by: Richard Hayden | last post by:
Hi, I have the following code: /******************************** file1.c #include <iostream> extern void dummy(); inline int testfunc() {
21
by: Rubén Campos | last post by:
I haven't found any previous message related to what I'm going to ask here, but accept my anticipated excuses if I'm wrong. I want to ask about the real usefulness of the 'inline' keyword. I've...
8
by: lasek | last post by:
Hi...in some posts i've read...something about using macro rather then function...but difference ??. Best regards....
6
by: Sharon | last post by:
Usually it is common to write the class member function in the class H file, but some people like to write the function body in the C++ file. Can anybody tell me what are the cases where inline...
32
by: chris.fairles | last post by:
Just want an opinion. I have an algorithm that needs to run as fast as possible, in fact. Its already too slow. I've done as much algorithmic changes as I can to reduce the amount of code, so now...
7
by: sam_cit | last post by:
Hi Everyone, I have a function declared as inline and i was wondering as to how it would be expanded by the compiler sample(int x) { if (x>0) sample(--x); printf("%d",x); }
1
by: DumRat | last post by:
Well, the results arouse curiosity. Check out for yourselves. http://www.thescripts.com/forum/threadnav617160-2-10.html
2
by: aaragon | last post by:
Hi everyone, I would like to create a very simple function: // header file inline void point_map() { PointMap pointMap = get(vertex_point_t(), g); } // main.cpp
15
by: Mahesh | last post by:
Hi, I need to know if stack frames are generated in case of a inline function execution or do they execute just like macros? if they execute like macros, then what is the need for having inline...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.