Inline functions

This is a discussion on Inline functions within the C Programming forums, part of the General Programming Boards category; I have reading about inline functions. It is basically a way to tell the compiler that try to put the ...

  1. #1
    Registered User
    Join Date
    Feb 2008
    Posts
    145

    Inline functions

    I have reading about inline functions. It is basically a way to tell the compiler that try to put the function inline mode, but it is not obligatory if the compiler dont find the way.
    I am programming a code where speed is essencial, that's the reason for I use inline functions.... so, is there any way to know if the function has benn inlined?
    If I could know that, that's allow me to change my code to avoid 'calls'.
    thx.

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    The only "portable" way to know if the function is inlined or not is to look at the generated assembler/machine code, really.

    Some (many) compilers will have warnings about "inlined function not inlined", but the next question is obviously "how do I make it go inlined", and whilst compilers often support way to either force inlining, or change the parameters that control inlining, there is again no standard way to do that.

    The other factor is that inlining fairly large functions is often meaningless, as the growth in code-size causes an increase in cache misses, which in turn means less performance. So if you do go changing the settings to inline more, make sure you benchmark the result.

    Inlining is really most efficient on one- or two-line functions.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    23,010
    My suggestion is: let the compiler handle inline functions. If you tell it to go wild with inline functions, it can often select functions it thinks might benefit from it.
    Instead, go for a profiler and find some bottlenecks in the code and focus on that instead.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Indeed, use the a profiler to figure out where the code is spending time. The analyze what the right solution is for that code.

    Just throwing inline all over the code rarely makes a big difference.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Inline Definitions and Declarations?
    By legit in forum C++ Programming
    Replies: 1
    Last Post: 06-15-2009, 02:59 PM
  2. Is it legal to have functions within functions?
    By Programmer_P in forum C++ Programming
    Replies: 13
    Last Post: 05-26-2009, 12:21 AM
  3. When to inline your *tors
    By Angus in forum C++ Programming
    Replies: 43
    Last Post: 10-29-2008, 04:38 PM
  4. conditional breakpoints and inline functions
    By Mario F. in forum C++ Programming
    Replies: 2
    Last Post: 08-10-2006, 09:30 PM
  5. inline friend functions.
    By sean in forum C++ Programming
    Replies: 2
    Last Post: 01-03-2002, 12:37 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21