Topic: modules sizes (inlines & templates)


Author: Ittay Freiman <ittay@tecnomatix.com>
Date: 1999/03/24
Raw View
hi,

1.  we've discovered that if the compiler decides it can't replace an
inline function call with the body of the function it creates a static
function in the object file with the same body and calls it instead.
this means that if i have a .h file with such an inline, it will appear
many times in the module (instanciated as a static function private to
each object file). my first question is weather i can change that
without changing the inline functions (they sometimes come from external
libraries)? can i force the compiler to always replace the call with the
body? can i cause the linker to recognise there are static instances of
the same inline and to combine them into one?

2. same idea for templates. i use a template ==> it is instanciated in
the object file. so our object file is again larger.  more over, some
compilers require that the code of the template be included in the .h
file ==> the methods are recognized as inlines ==> we have case #1 in a
much larger case. how can i remedy this?

thanx,
ittay

--
Ittay Freiman                      Tel   : 972-9-9594782/777
Tecnomatix Technologies Ltd        Fax   : 972-9-9544402
Delta House, 16 Hagalim Avenue
Herzliya 46733,  Israel            Email : ittay@tecnomatix.com



[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]






Author: Stephen.Clamage@Eng.Sun.COM (Steve Clamage)
Date: 1999/03/25
Raw View
Ittay Freiman <ittay@tecnomatix.com> writes:

>1.  we've discovered that if the compiler decides it can't replace an
>inline function call with the body of the function it creates a static
>function in the object file with the same body and calls it instead.
>this means that if i have a .h file with such an inline, it will appear
>many times in the module (instanciated as a static function private to
>each object file).

That is correct behavior according to the original C++ rules,
but not according to the standard. The standard now requires
that inline functions have external linkage unless declared
static. That in turn means that if the function is generated out
of line, there will be only one copy in the whole program.

There are many reasons why a function might be generated out
of line. The function might not match the compiler's limitations
on inlining. If you take the address of a function or call it
recursively, it must be generated out of line.

>my first question is weather i can change that
>without changing the inline functions (they sometimes come from external
>libraries)? can i force the compiler to always replace the call with the
>body? can i cause the linker to recognise there are static instances of
>the same inline and to combine them into one?

That will depend on the capabilities of your particlar
implementation. With a standard-conforming compiler, you won't
have a problem. Not many compilers have caught up with this
provision of the standard, however.

>2. same idea for templates. i use a template ==> it is instanciated in
>the object file. so our object file is again larger.  more over, some
>compilers require that the code of the template be included in the .h
>file ==> the methods are recognized as inlines ==> we have case #1 in a
>much larger case. how can i remedy this?

The way you deal with templates differs from compiler to compiler.
You have to consult the documentation. Some compilers offer
multiple options.

The standard provides for "external" templates, but few
compilers follow all its requirements yet.

--
Steve Clamage, stephen.clamage@sun.com
---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]





Author: "Ed Brey" <brey@afd.mke.etn.com>
Date: 1999/03/26
Raw View
Steve Clamage wrote in message <7dbgme$c7r$1@engnews1.eng.sun.com>...

>If you take the address of a function or call it
>recursively, it must be generated out of line.

It is not a requirement that a compiler must generate a recursive function
out of line.  If the compiler can determine a maximum depth of recursion at
compiler time, it can recursively inline the function if it chooses.

The reason that this point came to mind is that MS Visual C++ has a pragma
to limit the depth of inlined recursion.
---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]





Author: James.Kanze@dresdner-bank.com
Date: 1999/03/26
Raw View
In article <7dbgme$c7r$1@engnews1.eng.sun.com>,
  Stephen.Clamage@Eng.Sun.COM (Steve Clamage) wrote:

> The standard now requires
> that inline functions have external linkage unless declared
> static. That in turn means that if the function is generated out
> of line, there will be only one copy in the whole program.

Not quite.  It only means that the observable behavior of the program be
the same as if only one copy were generated.  In practice, I believe
that most compilers will suppress duplicate copies, in one way or
another, if only because it is the easiest solution for the special
cases (e.g. when I take the address of the function in two different
modules -- the addesses must compare equal), and once you've implemented
it, there's no reason not to use it systematically.  But the standard
certainly doesn't require it.

--
James Kanze                         mailto: James.Kanze@dresdner-bank.com
Conseils en informatique orientie objet/
                        Beratung in objekt orientierter Datenverarbeitung
Ziegelh|ttenweg 17a, 60598 Frankfurt, Germany    Tel. +49 (069) 263 17946

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own
---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]