[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.c++

name mangling

Megalo

11/3/2008 7:37:00 AM

why not make "name mangling" of C++ standard so should be possible
to call
the classes and the functions of C++ from other C++ compiler
[and other language too]
thanks



14 Answers

Zeppe

11/3/2008 12:00:00 PM

0

Megalo wrote:
> why not make "name mangling" of C++ standard so should be possible
> to call
> the classes and the functions of C++ from other C++ compiler
> [and other language too]

because one of the reason in having different mangling conventions is
exactly to forbid inter-compilers linking. Mangling is not the only
element of heterogeneity between compilers, but other issues have to be
considered as structure paddings, virtual functions tables, calling
conventions, and other implementation aspects of the standard.

Best wishes,

Zeppe

James Kanze

11/3/2008 12:02:00 PM

0

On Nov 3, 8:37 am, "Megalo" <m...@z.x> wrote:

> why not make "name mangling" of C++ standard so should be
> possible to call the classes and the functions of C++ from
> other C++ compiler [and other language too]

Because name mangling is only the tip of the iceberg. Different
compilers intentionally try to have different mangling, so that
you get an error at link time, rather than undefined behavior at
runtime. The C++ committee can't really address the issue,
because any layout rules would have to depend on the hardware;
normally (i.e. in the case of C), it is the platform which
defines the API. To date, very few platforms have done this for
C++ (Intel Itanium, I think). For proprietary platforms (e.g.
Solaris, Windows), one can argue that the API is defined as
whatever the owner's own C++ compiler (Sun CC, VC++) does, but
this isn't always well documented.

--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

Pawel Dziepak

11/3/2008 12:12:00 PM

0

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Megalo wrote:
> why not make "name mangling" of C++ standard so should be possible
> to call
> the classes and the functions of C++ from other C++ compiler
> [and other language too]
> thanks

C++ describes the programming language, not the way it is implemented.

For example, if somebody wants to create C++ runtime environment similar
to Java/.NET's ones, C++ standard compliance won't be broken. If
standard had described implementation details, it wouldn't have been
possible not to disobey some paragraphs.

Current situations, allow compilers creators to easily introduce new
ideas and mechanism that probably will make result code more efficient.

If you really want to call C++ function from other binaries you can use
things like:
extern "C" int function();

Pawel Dziepak
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail....

iEYEARECAAYFAkkO6ogACgkQPFW+cUiIHNrV1ACeJE/Q7gq88+4RIZT1gxzQK1QN
rmsAnRHfHIM2C2ghr7vzCuxyIuQUYCVF
=SM84
-----END PGP SIGNATURE-----

Megalo

11/3/2008 1:41:00 PM

0


"Pawel Dziepak" <pdziepak@quarnos.org> ha scritto nel messaggio
news:gempq9$4m5$1@registered.motzarella.org...
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Megalo wrote:
>> why not make "name mangling" of C++ standard so should be possible
>> to call
>> the classes and the functions of C++ from other C++ compiler
>> [and other language too]
>> thanks
>
> C++ describes the programming language, not the way it is implemented.
>
> For example, if somebody wants to create C++ runtime environment similar
> to Java/.NET's ones, C++ standard compliance won't be broken. If
> standard had described implementation details, it wouldn't have been
> possible not to disobey some paragraphs.

the above is also true

> Current situations, allow compilers creators to easily introduce new
> ideas and mechanism that probably will make result code more efficient.
>
> If you really want to call C++ function from other binaries you can use
> things like:
> extern "C" int function();

better
extern "C++" int function();

because extern "C" has already the meaning for "C function"

for me calling c++ function written in a assembly file from a
c++ program was ok

> Pawel Dziepak



tonytech08

11/3/2008 8:02:00 PM

0

On Nov 3, 1:37 am, "Megalo" <m...@z.x> wrote:
> why not make "name mangling" of C++ standard so should be possible
> to call
> the classes and the functions of C++ from other C++ compiler
> [and other language too]
> thanks

Wasn't name mangling implemented because of unevolved linker
technology when C++ was being designed? Something about not being able
to associate type information with symbols in a linker? And doesn't
modern linker technology provide mechanisms that would make name
mangling obsolete? Perhaps not all compilers do mangling anymore??

Pawel Dziepak

11/3/2008 8:14:00 PM

0

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

tonytech08 wrote:
> Wasn't name mangling implemented because of unevolved linker
> technology when C++ was being designed? Something about not being able
> to associate type information with symbols in a linker? And doesn't
> modern linker technology provide mechanisms that would make name
> mangling obsolete? Perhaps not all compilers do mangling anymore??

You can associate type information by adding type name to the function
name. That's how that information is (in general) stored. Technology
wasn't a problem. If you wanted not to change the symbol string *and*
store type information you would have to invent new executable and/or
relocatable files format (or improve existing ones), what is not a good
idea.

If all compilers used the same name mangling convention, there wouldn't
be such problem, despite the fact that name mangling would still be done.

Anyway, I don't think that it is a C++ standard thing to indirectly
create C++ compliant executable and/or relocatable file format.

Pawel Dziepak

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail....

iEYEARECAAYFAkkPW34ACgkQPFW+cUiIHNqK+QCglQtOd+7WPAsiUIdlkwaHePkg
8ukAn0i3E5/bwTnI7niGSWG9CdJAkfzU
=CFmT
-----END PGP SIGNATURE-----

James Kanze

11/3/2008 10:41:00 PM

0

On Nov 3, 2:41 pm, "Megalo" <m...@z.x> wrote:
> "Pawel Dziepak" <pdzie...@quarnos.org> ha scritto nel
> messaggionews:gempq9$4m5$1@registered.motzarella.org...

[...]
> > Current situations, allow compilers creators to easily
> > introduce new ideas and mechanism that probably will make
> > result code more efficient.

> > If you really want to call C++ function from other binaries
> > you can use things like:
> > extern "C" int function();

> better
> extern  "C++"  int function();

That's the default.

> because extern "C" has already the meaning for "C function"

I think his point was that almost all other langauges have the
capability to call a C function, so if you make your C++
function look like a C function, they can call it.

--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

James Kanze

11/3/2008 10:44:00 PM

0

On Nov 3, 9:13 pm, Pawel Dziepak <pdzie...@quarnos.org> wrote:
> tonytech08 wrote:
> > Wasn't name mangling implemented because of unevolved linker
> > technology when C++ was being designed? Something about not
> > being able to associate type information with symbols in a
> > linker? And doesn't modern linker technology provide
> > mechanisms that would make name mangling obsolete? Perhaps
> > not all compilers do mangling anymore??

> You can associate type information by adding type name to the
> function name. That's how that information is (in general)
> stored. Technology wasn't a problem. If you wanted not to
> change the symbol string *and* store type information you
> would have to invent new executable and/or relocatable files
> format (or improve existing ones), what is not a good idea.

Why not? I uses a linker as early as 1979 which supported
additional information about the function (other than just the
name). Mangling was introduced as a quick and dirty solution to
make things work with an existing linker (which was primitive
even by the standards back then). It turned out to work fairly
well, however, so no one has been motivated to develope other
solutions.

> If all compilers used the same name mangling convention, there
> wouldn't be such problem, despite the fact that name mangling
> would still be done.

The problem isn't that names are mangled differently. The
problem is that classes are laid out differently.

--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

Pawel Dziepak

11/3/2008 10:51:00 PM

0

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

James Kanze wrote:
> Why not? I uses a linker as early as 1979 which supported
> additional information about the function (other than just the
> name). Mangling was introduced as a quick and dirty solution to
> make things work with an existing linker (which was primitive
> even by the standards back then). It turned out to work fairly
> well, however, so no one has been motivated to develope other
> solutions.

Currently, on the majority of unix systems the main format is ELF which
doesn't provide such possibilities to save type information in other way
than modifying symbol's name. Of course, changing/improving that format
would make many things easier, but breaking compliance is not affordable
for people and companies that creates systems. Problems that would
appear are just more serious that benefits you can take from introducing
such format.

Pawel Dziepak
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail....

iEYEARECAAYFAkkPgFEACgkQPFW+cUiIHNrTyQCfcYSjpzx+LbLpceunror5Rmix
iQgAn3GVputZ8So5E9LXECIej4cYdHA+
=0QjE
-----END PGP SIGNATURE-----

Megalo

11/4/2008 9:01:00 AM

0

>"James Kanze" <james.kanze@gmail.com> ha scritto nel messaggio
>news:6582fa2d-0c67-4493-9207->7c157227e2a5@a29g2000pra.googlegroups.com...
>On Nov 3, 2:41 pm, "Megalo" <m...@z.x> wrote:
>> "Pawel Dziepak" <pdzie...@quarnos.org> ha scritto nel
>> messaggionews:gempq9$4m5$1@registered.motzarella.org...

>> > extern "C" int function();

>> better
>> extern "C++" int function();

>That's the default.

>> because extern "C" has already the meaning for "C function"

>I think his point was that almost all other langauges have the
>capability to call a C function, so if you make your C++
>function look like a C function, they can call it.

so you think that a
C++ [class] function in a .dll file
could have a name usable of a C language?

i would say their name should be the argument size they have, its individual
size
the way of call that function (stdcall ccall etc)

for example
int f(int, int, int)
could have the name

stdcall$int@32$f$int@32$int@32$int@32

if i have a type X where sizeof(X)==64
int f(X, X, X)
stdcall$int@32$f$X@64$X@64$X@64

it is the caller language that has to define type X, int32, in the
way it is like in the memory the C++ one