Results 1 to 4 of 4

Thread: What is the use of inline function

  1. #1
    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.

  2. #2
    Join Date
    May 2008
    Posts
    2,389

    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'

    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()
    {
    }

  3. #3
    Join Date
    Feb 2008
    Posts
    1,852

    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:

    #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;

    }

  4. #4
    Join Date
    Jan 2008
    Posts
    1,521

    Re: What is the use of inline function

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


    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");
    }

Similar Threads

  1. Advantages of Inline Function
    By Sonam Goenka in forum Software Development
    Replies: 4
    Last Post: 08-02-2010, 11:07 AM
  2. List the differences between macro and inline() : C++
    By Garett in forum Software Development
    Replies: 4
    Last Post: 25-01-2010, 12:49 PM
  3. Don't know about an inline class
    By Bottlenecked in forum Software Development
    Replies: 5
    Last Post: 25-01-2010, 09:57 AM
  4. Problem with static and inline in C++
    By Sujit15 in forum Software Development
    Replies: 3
    Last Post: 06-05-2009, 01:15 PM
  5. Virtual inline in C++
    By Jacek in forum Software Development
    Replies: 5
    Last Post: 27-12-2008, 12:57 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,751,682,250.44287 seconds with 16 queries