Re: why not inline all functions?

Ben Elliston <>
11 Jun 1998 16:13:27 -0400

          From comp.compilers

Related articles
why not inline all functions? (Mark Sanvitale) (1998-06-09)
Re: why not inline all functions? (Clifford Click) (1998-06-11)
Re: why not inline all functions? (Phillip Toland) (1998-06-11)
Re: why not inline all functions? (Joerg Schoen) (1998-06-11)
Re: why not inline all functions? (Ben Elliston) (1998-06-11)
Re: why not inline all functions? (Andy Ayers) (1998-06-11)
Re: why not inline all functions? (1998-06-11)
Re: why not inline all functions? (Thomas Niemann) (1998-06-11)
Re: why not inline all functions? (1998-06-11)
Re: why not inline all functions? (1998-06-18)
Re: why not inline all functions? (Hans Walheim) (1998-06-18)
| List of all articles for this month |

From: Ben Elliston <>
Newsgroups: comp.compilers
Date: 11 Jun 1998 16:13:27 -0400
Organization: Cygnus Solutions
References: 98-06-032
Keywords: optimize, practice

Mark Sanvitale <> writes:

> Functions are great for making written code (C, C++, etc.) mode
> readable and structured, however, they do not seem to make much sense
> when you get down to the raw machine code which actually is executed
> by a processor.

There is still one purpose for retaining this structure in the
executable. I'll get to this below.

> The output of such a compiler would be larger binary files (since
> every call to a function would expand to the entire function body)
> however the execution time for such a program should be improved
> (relative to a non-inlining compiler) by a factor proportional to the
> number of function calls in the program.

I remember reading somewhere that, in fact, by inlining functions like
this, the potential for optimisations is greater. My intuition can
see why. But code bloat would still be significant.

> Perhaps compilers already take advantage of the idea I have outlined or
> perhaps there are some problems with the idea which I don't know about
> (an old C++ book I have says, "Compiler limits prevent complicated
> functions from being inlined," but no further explanation is given.

In my opinion, the major drawback to inline functions is that they are
much harder to debug. Suppose you have code which frequently calls:


And you suspect a bug in your square root function. If my_sqrt() were
inlined at every point that it was used, it would be impossible to set
a breakpoint at the start of my_sqrt() and to examine an invocation of
this function. It becomes a real headache.

Furthermore, it helps a great deal to know the calling sequence at
runtime in case, say, an assertion fails and you need to know how your
function was called and what the arguments were.

Ben Elliston
[That's not a very persuasive argument. There's no reason the debugger
can't know all the places the inline function was called and put breakpoints
on all of them. It has to do something similar in compilers that unwind
loops already. -John]


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.