1. Home
  2. Computing & Technology
  3. C / C++ / C#

Definition of Inline Functions

By David Bolton, About.com

Definition: C and C++ allow you to make functions inline. This means that instead of the compiler inserting code to call a routine with the overhead of pushing parameters on the stack, the function machine code is inserted into the code where the function was called. This can speed up code inside loops.

This doesn't happen automatically- inline is generally regarded as a hint for the compiler to do this if it can. The downside of inlining is that it can bloat your code size if the function is called from many places.

In C (and non class functions in C++) inlining is done by adding the word inline before the function name.

inline int aminusb2(int a, int b) {
return (a-b)*(a- b) ;
}
In C++ class functions, inlining the function is done by including the code in the declaration. In the example below, add() is an inline function.
class fred { public:
add(int a,int b) {
return a+ b;
}
} ;

C# Inline Functions

C# does not have any equivalent way of inlining at the language level, however the .NET framework does provide optimizations like inlining at the code level.

Glossary:

A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Examples:
Inlining is preferable to macros as it is generally safer.
Explore C / C++ / C#
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. C / C++ / C#

©2009 About.com, a part of The New York Times Company.

All rights reserved.