Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

What are Inline Functions and how to use it?

Status
Not open for further replies.

agg_mayur

Member level 3
Joined
Feb 25, 2010
Messages
66
Helped
3
Reputation
6
Reaction score
3
Trophy points
1,288
Location
India
Activity points
1,715
Hi All,

What are inline functions and how can it be used?? What will be the advantage for using the inline functions and macros?
 

A normal function is 'called' everytime it is used. An inline function duplicates the code everytime. This saves time but wastes space, so it depends on which is most important to you.

Keith
 

Inline functions are part of the C++ language - I have never seen a C compiler that has the facility (but there could be). They work in a similar way to parameterised macros in C (but at compile time rather than during preprocessing). The inline specifier requests the compiler to replace calls to the function with the compiled code of the function body thus saving the overhead of a function cal. The inline specifier is a request and may be ignored by the compiler. In any case it should be used sparingly and only with small functions where the overhead of the function call (making copies of the actual parameters and calling the function) may exceed the computations within the function.
 

Normally the functions are coded as subroutines which are called every time you call that function.
Each time you make a call to a function there is an overhead of putting all the variables into stack, defining the return location, passing the parameter and they are all termed as function overhead.

Inline eliminates the time overhead when a function is called by forcing the compiler to hard code the function content in each position that it is called.
This is most beneficial for functions that are called only once, for example initialization functions for the microcontroller,or in functions that speed is important.
When you use inline for functions which are called many times you get faster execution speed but you increase the code size because you have the same code replicated many times.
Normally the compiler decides if it will use inline in each function or your code but you can use inline directive to force this for a specific function.

Alex
 
Inline functions are part of the C++ language - I have never seen a C compiler that has the facility...

I have only used three compilers and it exists in all of them, CodevisionAVR, AVRGCC and Keil uvision

Alex
 

Thankyou all for giving such nice explanations.
 

I agree with keith1200rs inline function will do executions fast but think about the memory space.

Regards
Chanchal
 

Interesting that inline functions are now available with some C compilers (useful for time critial code in embedded systems ?). I found then useful in C++ classes for very short member functions for manipulating data hidden within the class but otherwise tended to avoid them
Remember an inline function must be defined (the body of the function specified) before it is called, not just a function prototype declared.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top