Re: C++
On Feb 23, 1:14 pm, Juha Nieminen <nos...@thanks.invalid> wrote:
James Kanze wrote:
can somebody explore me more on Concept of Name Mangling
used by C++ compilers.
An implementation detail, which varies from one compiler to the
next.
Which is a shame, really. It hinders C++'s capabilities at creating
shared and precompiled libraries.
Not really. What hinders C++'s capabilities here is the lack of
platform standard API's. The reason you can't link code
compiled with Sun CC with that compiled with g++ is because Sun
CC and g++ lay out vtables, virtual inheritance, etc.,
differently.
All that the different name manglings mean is that you'll get an
error at link time, rather than a core dump at run time.
Either all C++ shared/precompiled libraries and C++ programs
in a system must be compiled with the same compiler, or if
several different compilers are used, they all must use the
exact same name mangling system which, as you say, is often
not the case.
Not just the same name mangling system, but the same conventions
throughout. Class layout, exception handling, calling
conventions, etc., etc.
If name mangling was standardized, it would greatly increase
the usability of C++ to create shared and precompiled
libraries usable among different compilers.
Not really. It would greatly increase the time spent in finding
errors because two libraries were compiled using different
conventions.
(Note that even today, both Sun CC and g++ use somewhat
different layouts for some of the standard classes, depending on
compiler options. Without changing mangling. I've already lost
a fair amount of time because of it: one library being compiled
with different options than the client code.)
If I'm not mistaken, in the C world name mangling has been
long ago "standardized" (if not de jure, at least de facto),
which is why C is so much more usable for precompiled
libraries: A library created by any C compiler is usable by
any another C (and even C++) compiler.
The reason why C works in this case is because most platforms
define a standard C API, to which all C compilers adher. There
have been efforts in this direction for C++, at least on some
platforms, but on the whole, not nearly as much as one would
like.
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34