Inline Functions

05 May 2014

Programmers’ theoretical minimum: rule of thumbs for defining inline functions in C++

In C++ there is a special keyword called inline that allow you to declare a function that is expanded inline rather than called through the usual function call mechanism.

The main reason for making a virtual function inline is to generate more efficient object code. However, overuse of inlining can actually make programs slower. Not all functions are always inlined, even if they are declared as such. A tipical example are recursive functions which are not normally inlined.

Below is reported a rule of tumbs for defining inline functions:

  • they are small (e.g. 10 lines of code or less)
  • they don’t contains loops or switch statements
  • they are not recursive

##Further Information


Google C++ Style Guide, Revision 3.274

blog comments powered by Disqus