+ Reply to Thread
Results 1 to 2 of 2

Thread: What is inlining a function in C++?

  1. #1

    What is inlining a function in C++?

    Hi All,

    What is inline a function in C++?

    How can I get benefit using it?


  2. #2
    Senior Member
    Join Date
    Feb 2012

    'Inline' keyword is used to inline the method code where it is used. So there is no cost of method call and parameter push/pop.

    It is compiler who decides whether to inline function or not.

    Below is example of inline function.

    class CInline
    	int m_nValue ;
    		m_nValue = 0 ;
    	inline int GetValue()
    		return m_nValue ;
    } ;
    void UseInline()
    	CInline objInline ;
    	int nValue = objInline.GetValue() ;
    a. Please note that inline function should be define and declare in the header file.
    b. It is possible that Compiler may not make the method inline even if it defined so.
    c. Inline functions should qualify some criteria to be really inline.
    d. Inline functions should be short in code size.
    e. Inline functions should not be recursive.
    f. On Microsoft Visual Studio, user can use "__forceinline" keyword to force the method to be inline. This should be used with very much care. It can degrade performance.
    g. If user wants use inline function that is recursive then follow this link:

    Advantage of using inline function:
    a. There is no function call overhead so it increases performance.
    b. It is being compiled so it is better than MACRO! This increases type safety.

    Disadvantages of using inline function:
    a. It increases code size if not properly used.


+ Reply to Thread

Tags for this Thread


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts