Re: inline functions not inlined



Ian Collins <ian-news@xxxxxxxxxxx> writes:
Keith Thompson wrote:
Bilgehan.Balban@xxxxxxxxx writes:

If I define an inline function in one .c file, and use it from another,
after compiling and linking the two, it seems the function is not
inlined but rather called as a regular function. I would expect to see
it inlined during linkage of the two object files. Does inlining only
occur if the inline function is defined within the same file that it is
called?
C99 6.7.4p5:
A function declared with an inline function specifier is an
_inline function_. The function specifier may appear more than
once; the behavior is the same as if it appeared only once. Making
a function an inline function suggests that calls to the function
be as fast as possible. The extent to which such suggestions are
effective is implementation-defined.
So an implementation isn't required to do anything special with an
inline function (it's like "register" in that sense).

Maybe it's an added complexity like 'register' which the language
would be better off without. A hangover from older compilers with
poor optimisation.

Let the optimiser to the work.

I suspect that modern compilers aren't as good at automatically
inlining functions as they are at assigning variables to registers,
and that user-controlled inlining still makes sense. (I have no hard
data to back that up.)

Providing inline could also tend to discourage the somewhat dangerous
use of macros as "faster" functions.

--
Keith Thompson (The_Other_Keith) kst-u@xxxxxxx <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
.



Relevant Pages

  • Re: Experiences using "register"
    ... Because it adversely affects code size is one thing I can think of ... inlining may even decrease the code size. ... The main purpose of inline is to take away the function call and return ... Again the standard inline keyword is like register: ...
    (comp.lang.c)
  • Re: Best charting package
    ... You're right about the property inlining, but it is present only in the ... ..NET framework 2.0 and to a certain level - for example having a simple ... Inline functions / properties are badly missing. ... MSVC would ignore the register ...
    (microsoft.public.dotnet.framework.windowsforms.controls)
  • Re: a little mistake
    ... Also the use of "inline" for that function is redundant. ... compilers will do it anyways and it isn't portable across all compilers ... int main ... Calling function would be part of the users code. ...
    (comp.lang.c)
  • Re: on nested functions called only once
    ... Scheme implementations" use optimizing compilers. ... compiled systems) do not bother to inline local procedures. ... Ikarus and Larceny both use optimizing compilers, ...
    (comp.lang.scheme)
  • Re: Semantics of Inline vs non-Inline
    ... > that if the semantics are to be the same for inline and non-inline ... then it should be the compilers responsibility to ensure ... version may use register and pass by copy for parameter passing. ...
    (comp.lang.ada)