Re: Name mangling

Thant Tessman <thant@acm.org>
2 Jul 2001 12:30:52 -0400

          From comp.compilers

Related articles
Name mangling youngwk@yahoo.com (Young Wei Kuan) (2001-07-01)
Re: Name mangling thant@acm.org (Thant Tessman) (2001-07-02)
Re: Name mangling fjh@cs.mu.OZ.AU (2001-07-03)
Re: Name mangling toon@moene.indiv.nluug.nl (Toon Moene) (2001-07-06)
Re: Name mangling alainm@cup.hp.com (Alain Miniussi) (2001-07-06)
Re: Name mangling dosreis@cmla.ens-cachan.fr (Gabriel Dos Reis) (2001-07-17)
Re: Name mangling alainm@cup.hp.com (Alain Miniussi) (2001-07-18)
Re: Name mangling dosreis@cmla.ens-cachan.fr (Gabriel Dos Reis) (2001-07-23)
| List of all articles for this month |
From: Thant Tessman <thant@acm.org>
Newsgroups: comp.compilers
Date: 2 Jul 2001 12:30:52 -0400
Organization: Standard Deviance
References: 01-07-008
Keywords: GCC, C++, debug
Posted-Date: 02 Jul 2001 12:30:52 EDT

Young Wei Kuan wrote:


> I understand g++ 3.0 has changed its name-mangling scheme.
> Can anyone explains what name mangling does exactly? Why is
> it that object code compiled by g++ 2.95 is incompatible with
> that of gcc3.0?


In C++ you can define several functions that all use the same name,
but apply to different argument types (or reside in different
namespaces). Since C++ implementations typically use C-style linkers,
a trick for making sure these overloaded names are unique is to build
a new name out of the old name and the argument types. This is called
name mangling.


Since you're using g++ you probably have access to 'nm' and 'c++filt'.
You can use the 'nm' utility on a C++ executable to see the mangled
names, and you can use the 'c++filt' utility to translate the mangled
names into their original C++ syntax.


The C++ standard doesn't mandate how these names are to be built, so
different compilers, and even different revisions of the same compiler
may use different mangling algorithms.


If you want to call a C function from a C++ program, you need to use
the 'extern "C"' declaration. This basically tells the compiler to
turn off name mangling.


Hope this helps.


-thant



Post a followup to this message

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