inline request and compiler rejection

C

coal

I think your answer assumes that buying faster hardware is no big
So far I've always managed to justify the cost against the saving in
developer time, either to my employer or to myself (I've just added a
new core i7 box to my farm).

Well you don't really say what you favor between the header only
approach and the separated approach. But it seems like you're
saying use the header only approach and add hardware. I don't
recall what your area of work is now. If you sell binaries I
can see it working, but if you sell libraries, your users will
wish they also could afford to buy faster hardware. Since the
economy is rough, it makes sense not to push out anything that
overly taxes their systems/resources.

Brian Wood
Ebenezer Enterprises
www.webEbenezer.net
 
I

Ian Collins

Well you don't really say what you favor between the header only
approach and the separated approach.

I don't have a preference.

The limits of current compilers force us to adopt a header only approach
for templates, so our hands are some what tied.
But it seems like you're
saying use the header only approach and add hardware.

I'm not!

I'm saying don't get hung up restructuring code to get build times down,
throw hardware at the problem. The money's better spent elsewhere.
I don't recall what your area of work is now.

Mainly embedded. Code structure tends to be based on the requirements
of the embedded compiler. More inline code gives the tool chain the
ability to balance code size with execution speed. At one extreme we
can inline everything for speed. At the other the linker-optimiser can
perform duplicate code removal to optimise for space.

During development most builds are run on the development hosts. The
target compiler code layout requirements many not be the best for the
development host, so the best solution is more and faster hosts.
 
J

James Kanze

* James Kanze:
I think you missed a couple of "can" and other qualifiers.

Maybe. I was reacting to a statement "I inline almost all
non-template function definitions." At one point, I did
qualify my statement with a "generally". The basic rule, of
course, is to prefer non-inline unless there is a good
reason for doing otherwise. There are sometimes good
reasons, and I'm the first to admit that if optimizing is
necessary, inlining (if that suffices) is a lot cheaper than
using some more complicated algorithm.
Especially for libraries of basic functionality, or in a
known "environment" where header pollution isn't an issue,
inlining is very useful for header-only modules without
introducing any extra coupling (coupling in addition to
what one already has anyway).

In certain contexts, yes. I tend to inline the virtual
destructor of an interface, for example---it does seem silly
to need to deliver an object file for one function, which by
definition will be empty, and is only present in order to
make it virtual.
As an example, one reason that much of Boost is so useful
is that a great many of the modules can be employed
without compiling them separately; just include the
relevant header and that's that.

That's a very important feature in Boost, because they've
adopted a build system which creates a lot of extra
problems. So you don't want to build it if you can avoid
it. The issue would be a lot less if they had a better
build system. And it's a non-issue if you get Boost
pre-installed (as you do with most Linux).

Note too that in a system library, which is presumably
stable, the "coupling" isn't so much an issue. If I change
the version of Boost (or the compiler, or the standard
library), I have to rebuild everything anyway. It's not
something I do very often, however, and it's something that
needs planning and scheduling---it's normally no problem to
schedule the rebuild on a week-end, so even compile times
aren't an issue.
So in a way inlining is the C++ counter-weight to the
language's lack of real modules.
For with real modules header-file modules would presumably
have had no advantage.

With real modules, the whole model would be different.
Basically, you would declare your "interface" (the publicly
accessible definitions) in one file, and your
"implementation" in as many different files as you want.
The compiler would take care of straightening things out.

You can, in fact, come fairly close to this in effect with
header files, as long as no templates are involved. But
there's always a bit of "playing with fire" involved.
 
J

James Kanze

With a decent OS and enough RAM, most (include) files will be fetched
and cached only once.

Not if the build is distributed. They'll be fetched and
cached (generating significant network traffic) once per
machine.

(It also occurs to me that not everyone has the priviledge
of being able to develop under a "decent OS". Or with
"enough RAM", for that matter, when "enough RAM" is
significantly more than 4GB.)
Caching does.

Only once per machine.
The network limit is usually writing back the compiler's
output, which is much less than its input.

I'll admit that the actual measurements I'm familiar with
date somewhat, but even today, a complete rebuild of my
library on a very up to date Linux based PC takes a couple
of minutes. Not the sort of thing I really want to wait for
if I can avoid it.
 
C

coal

I don't have a preference.

The limits of current compilers force us to adopt a header only approach
for templates, so our hands are some what tied.


I'm not!

I'm saying don't get hung up restructuring code to get build times down,
throw hardware at the problem.  The money's better spent elsewhere.


Mainly embedded.  Code structure tends to be based on the requirements
of the embedded compiler.

I'm working on adding an option that allows users to choose between
header only and interfaces and implementations. I'm thinking of
using
your phrase, "code structure," in the user interface:

Code Structure
__ Integrated -- header-only
__ Separated -- two files

Thank you. I'm noticing that the size of the stripped .o file
using the separated approach, 10,120 bytes, is more than ten
times larger than the strippped size when it's header only --
780 bytes.
 More inline code gives the tool chain the
ability to balance code size with execution speed.  At one extreme we
can inline everything for speed.  At the other the linker-optimiser can
perform duplicate code removal to optimise for space.

When I go on and build executables, the stripped, separated version
is 14,368 bytes and the stripped, header only version is 3736 bytes.
I'm using gcc 4.3.2 with -O3 for all of this. So now I wonder if
it's worth it to provide this option. It doesn't hurt to have it,
but I'm not sure if it's as beneficial as I thought.

One of the helpful aspects of our on line approach is we can tell
how the software is being used and which options are heavily/
lightly used. If it doesn't get used, we'll know and remove it,
simplifying things for both users and us. Compiler vendors really
need to have that sort of info as well and I've been pushing for on
line compilers for years. Meanwhile gcc is being developed in C as
of March 22, 2009.


Brian Wood
Ebenezer Enterprises
www.webEbenezer.net
 
P

Pranav

If we declare and define a function inside a class it is considered as
inline function(although the compiler has the the rights decide
whether to consider the req. or not). Is PURE VIRTUAL function
considered as the inline function and makes a request to compiler?
 
A

Alf P. Steinbach

* Pranav:
If we declare and define a function inside a class it is considered as
inline function(although the compiler has the the rights decide
whether to consider the req. or not). Is PURE VIRTUAL function
considered as the inline function and makes a request to compiler?

You cannot provide a definition of a pure virtual routine inside a class, hence
the question's main assumption is invalid.

It seems that nobody knows why, it just is that way (historical accident?).

But you can provide a definition outside the class definition.


Cheers & hth.,

- Alf
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,571
Members
45,045
Latest member
DRCM

Latest Threads

Top