Thread: On the use of inline

  1. #1
    Registered User
    Join Date
    May 2008
    Posts
    110

    On the use of inline

    I have read the following statement (partial quote):

    "A reasonable rule of thumb is to not put inline at functions that have more than 3 lines of code in them."

    Does this rule of thumb apply if the three lines call a massive chunk of code, e.g., from a library?

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    37,533
    > Does this rule of thumb apply if the three lines call a massive chunk of code, e.g., from a library?
    No, it applies to the inline function only.

    The naive interpretation of inline is that the body of the function is copy/pasted into the place where you call this function. The thinking goes that if your inline function is large, then all you end up with is executable code bloat. This might make the code worse, if the inlined function is called frequently. Instead of 1 copy of the function residing in cache and being called, you have multiple clones which need to be fetched on demand.

    It depends on how well your optimiser handles the code inserted into the call site, and whether the compiler itself treats inline in some kind of advisory way and makes choices for you.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. inline in gcc
    By KIBO in forum C Programming
    Replies: 4
    Last Post: 06-23-2008, 06:41 AM
  2. Inline asm
    By brietje698 in forum C++ Programming
    Replies: 5
    Last Post: 11-11-2007, 02:54 PM
  3. Inline: I don't get it
    By Epo in forum C++ Programming
    Replies: 17
    Last Post: 06-21-2004, 12:13 AM
  4. Inline ASM ???????
    By datainjector in forum C Programming
    Replies: 5
    Last Post: 09-03-2002, 12:43 PM

Tags for this Thread