Mar 10, 2009

What Does It Mean For a C++ Function To Be Inline?

The function is placed in the code, rather than being called, similar to using macros (conceptually)

This can improve speed (no function call), but causes code bloat (if the function is used 100 times, you now have 100 copies)

You should note this does not force the compiler to make the function inline, and it will ignore you if it thinks its a bad idea. Similarly the compiler may decided to make normal functions inline for you.

This also allows you to place the entire function in a header file, rather than implementing it in a cpp file (which you cant anyways, since then you get an unresolved external if it was declared inline, unless of course only that cpp file used it).

No comments:

Carlo Cipolla's Laws of Stupidity

    "By creating a graph of Cipolla's two factors, we obtain four groups of people. Helpless people contribute to society but are...