Advantages of using inline functions

Discussion in 'Mac Programming' started by sheepopo39, Dec 14, 2009.

  1. sheepopo39 macrumors 6502

    Sep 18, 2008
    I just read over inline functions and I understand what it does, but I don't really see how you're gaining anything when you use it, because if you were to call the function (not inline), that code in the function would still be executed like it was in that part of the code. So then, what's the difference? :confused:
  2. Guiyon macrumors 6502a

    Mar 19, 2008
    North Shore, MA
    It's a code size/speed tradeoff; when you inline a function you effectively remove the function call overhead by inserting the code directly into the locations where it is called. In functions which are called often this can result in a significant speed boost. This does cause a potentially significant increase in the code size of the program unless the function is very small. Inlining is one of the things that you are probably best off leaving the compiler to decide unless you really know what you are doing as inlining some functions can actually cause a performance hit instead of a boost.
  3. Sander macrumors 6502

    Apr 24, 2008
    In fact, the compiler is free to ignore the "inline" keyword. Just like it quite likely ignores the "register" keyword.

Share This Page