TITLE: Use inlining judiciously This example comes from "Effective C++" by Scott Meyers, p. 107-110. Portions which have been deleted are indicated with an ellipsis. The whole idea behind an inline function is to replace each call of that function with its code body, and it doesn't take a PhD in statistics to see that this is likely to increase the overall size of your object code. ... On machines with virtual memory, inline-induced code bloat can lead to pathological paging behavior. ... On the other hand, if an inline function body is very short, the code generated for the function body may actually be smaller than the code generated for a function call. ... Bear in mind that the inline directive is a hint to the compiler, not a command (just like register). That means the compiler is free to ignore your inline directive whenever it wants to, and it's not that hard to make it want to. ... Most compilers will issue a warning ... if they fail to inline a function you've asked them to. ... Inline function definitions are virtually always put in header files. This allows multiple translation units (source files) to include the same header files and reap the advantages of the inline functions that are defined within them. ... ... Most compilers treat an inline function that they aren't inlining as if the function had been declared static - that is, local to the file currently being compiled. ... This strategy eliminates the link-time problem, but at a cost: each translation unit that includes the definition of f will have its own static copy of f. This leads to a stunning realization. If an inline function isn't inlined, you still pay for the cost of a function call at each call site, but you also suffer an increase in code size, because each translation unit that includes f's definition gets its own coyp of f's code! There's more. Sometimes your poor, embattled compiler has to generate a function body for an inline function even when the compiler is perfectly willing to inline the function. In particular, if your program ever takes the address of an inline function, the compiler must generatte a function body for it: how can it come up with a pointer to a function that doesn't exist? inline void f() { ... } // as above void (*pf) () = f; // pf points to f main () { f(); // an inline call to f pf (); // a non-inline call to f // through pf } ... Initially don't inline anything, or at least limit your inlining to those functions that are truly trivial. ...