Thread: inline in gcc

  1. #1
    Registered User
    Join Date
    Jan 2007
    Posts
    330

    inline in gcc

    I want to make an external swap function but I want to make it inline and for some reason I dont want to use a macro. Can I depend on gcc to inline a 3 line function when using the inline keyword?

  2. #2
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    It doesn't really matter if GCC doesn't make it inline, does it? GCC will inline your function if it thinks it's the best idea. In fact, it will probably do so anyway, even if you don't use the inline keyword. And it doesn't matter to you. The code still does the same thing whether the function is inlined or not. It might be more efficient to inline it, but that's for GCC to decide.

    I would guess, however, that a three-line function which is called several times has a very good chance of being inlined. Especially if you use -O2 or -O3 to tell GCC to optimise for speed (as opposed to -Os, for space optimising).
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  3. #3
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    However, in a "external function", that sounds like a different source file, in which case the inline keyword will not help. Moving the function to a header-file that is included where the function is called would be one choice.

    --
    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.

  4. #4
    Registered User C_ntua's Avatar
    Join Date
    Jun 2008
    Posts
    1,853
    There is also a small difference inlining in C89 and C99 mode

  5. #5
    Registered User
    Join Date
    Jan 2007
    Posts
    330
    Quote Originally Posted by matsp View Post
    However, in a "external function", that sounds like a different source file, in which case the inline keyword will not help. Moving the function to a header-file that is included where the function is called would be one choice.

    --
    Mats
    thanks, that's what I wanted to know

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Profiler Valgrind
    By afflictedd2 in forum C++ Programming
    Replies: 4
    Last Post: 07-18-2008, 09:38 AM
  2. Code review
    By Elysia in forum C++ Programming
    Replies: 71
    Last Post: 05-13-2008, 09:42 PM
  3. gcc and inlining
    By Laserve in forum C Programming
    Replies: 4
    Last Post: 11-24-2006, 03:31 AM
  4. Certain functions
    By Lurker in forum C++ Programming
    Replies: 3
    Last Post: 12-26-2003, 01:26 AM
  5. gcc inline asm: illegal instruction (core dump)
    By Sargnagel in forum C Programming
    Replies: 4
    Last Post: 10-28-2003, 01:41 PM