C++ Tutorial - Inline Functions

CoderSource.net
C++ Tutorial - Inline Functions
Rating:

Date: 5/1/2004 12:00:00 AM

   When a function is declared inline, the function is expanded at the calling block. The function is not treated as a separate unit like other normal functions.

   But a compiler is free to decide, if a function qualifies to be an inline function. If the inline function is found to have larger chunk of code, it will not be treated as an inline function, but as like other normal functions.

   Inline functions are treated like macro definitions by the C++ compiler. They are declared with the keyword inline as follows. 

   //Declaration for C++ Tutorial inline sample:
    int add(int x,int y);

   //Definition for C++ Tutorial inline sample:
    inline int add(int x,int y)
    {
        return x+y;
    }
    In fact, the keyword inline is not necessary. If the function is defined with its body directly and the function has a smaller block of code, it will be automatically treated as inline by the compiler. 

   As implied, inline functions are meant to be used if there is a need to repetitively execute a small block of code, which is smaller. When such functions are treated inline, it might result in a significant performance difference.

You Can Rate this Article, if you are Logged In      
 

More Links from CoderSource.net:

 
Refer to a Friend:

Your Details:

Name:     e-mail:

Friend Details:

Name:    e-mail:    


MENU
Home
MFC 
C++
.Net
WIN32
Programming
Forum
My Articles
Add to Google
Add to My Yahoo!
Welcome to Codersource.Net Login | Register | Faq  

SEARCH
Google
 

NOTES:


Thanks for visiting our CoderSource.net. This site will be improved with more articles. Interested visitors can also submit their articles through the Submit Article link.Your article will also be published after due consideration by the editor. 

© Copyright 2003. All rights on content reserved by CoderSource.net. Contact    About Us