Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 19-11-2009
Member
 
Join Date: Jan 2009
Posts: 45
What is the use of inline function

I am beginner in the field of the programming. I was getting confused regarding the inline function.

What is the main use of inline function? is it any special function?

Anybody know the syntax for inline function? Please recommend me to find out solution for this along with it's example.
Reply With Quote
  #2  
Old 19-11-2009
Member
 
Join Date: May 2008
Posts: 2,383
Re: What is the use of inline function

Inline function is used for accessing private data members. The main use of this functions is to return state information of the object. Short functions are very sensitive to the overhead of the function calls. Longer functions spend proportionally very less time as compare to short functions in the calling or returning sequence.

following is the example of 'inline function'

Quote:
class Point
{
public:
// Define "accessor" functions as
// reference types.
unsigned& x();
unsigned& y();
private:
unsigned _x;
unsigned _y;
};

inline unsigned& Point::x()
{
return _x;
}
inline unsigned& Point::y()
{
return _y;
}
int main()
{
}
__________________
The FIFA Manager 2009 PC Game
Reply With Quote
  #3  
Old 19-11-2009
Member
 
Join Date: Feb 2008
Posts: 1,848
Re: What is the use of inline function

If we don't know yet, when in our program code there's a function, the program jumps to the location of the function and when it reaches the at the end of the function it comes back. This 'jumping' is happened often and it takes time.

The solution on above problem is to use inline functions. An 'inline function' is called the compiler & replace the call with the appropriate function code.


Example:

Quote:
#include "stdafx.h"
#include <iostream>

using namespace std;

inline int average(int a, int b)

{

return (a + b) / 2;

}

int main()

{

int result = average(15, 25);

cout << "The average of number 15, 25 is " << result << "\n";

return 0;

}
Reply With Quote
  #4  
Old 19-11-2009
Member
 
Join Date: Jan 2008
Posts: 1,515
Re: What is the use of inline function

Something below might help you to understand the use of inline function in 'c' language.

Quote:

inline.h:

#include<stdio.h>

extern inline void abc(void){ // GNU C uses this definition for inlining only
printf("From inline.h\n");
}

main.c:

#include "inline.h"

int main(void){
void (*pTwo)() = abc;
two();
(*pTwo)();
}

abc.c:

#include<stdio.h>

void abc(){
printf("In abc.c\n");
}
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "What is the use of inline function"
Thread Thread Starter Forum Replies Last Post
Advantages of Inline Function Sonam Goenka Software Development 4 08-02-2010 11:07 AM
List the differences between macro and inline() : C++ Garett Software Development 4 25-01-2010 12:49 PM
Don't know about an inline class Bottlenecked Software Development 5 25-01-2010 09:57 AM
Problem with static and inline in C++ Sujit15 Software Development 3 06-05-2009 01:15 PM
Virtual inline in C++ Jacek Software Development 5 27-12-2008 12:57 PM


All times are GMT +5.5. The time now is 04:57 PM.