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?
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?
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.
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.
There is also a small difference inlining in C89 and C99 mode