home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!ogicse!hp-cv!sdd.hp.com!usc!rpi!think.com!barmar
- From: barmar@think.com (Barry Margolin)
- Newsgroups: comp.lang.c++
- Subject: Re: Libraries which depend on compiler (mangling).
- Message-ID: <16u0glINN84a@early-bird.think.com>
- Date: 19 Aug 92 17:31:01 GMT
- Article-I.D.: early-bi.16u0glINN84a
- References: <Bt8922.ED4@fulcrum.bt.co.uk>
- Organization: Thinking Machines Corporation, Cambridge MA, USA
- Lines: 37
- NNTP-Posting-Host: telecaster.think.com
-
- In article <Bt8922.ED4@fulcrum.bt.co.uk> rct@fulcrum.bt.co.uk (Richard Taylor) writes:
- >I suspect this is probably an old chesnut, but I'm new to C++, and have just
- >come across the fact that different compilers mangle names in different
- >ways (g++ and cfront, in particular).
- >This means that when I purchase a library of objects (which happen to have
- >been compiled with cfront) I cannot compile my own code (with g++) and link
- >it together with the object library, without also purchasing cfront. In a
- >world of releatively portable code, this is an incredible oversight.
-
- Is this in the FAQ yet?
-
- You're confusing portability with interoperability. Name mangling is only
- a small part of the interoperability problem between code generated by
- different compilers. Other differences include: layout of virtual tables,
- layout of class members (in particular, the order of members when multiple
- inheritance is used), how "this" is passed in the calling sequence of
- member functions, and how global initializers are executed.
-
- Until all such things are standardized, there's no point in standardizing
- the name mangling. In fact, compilers are *encouraged* to use unique
- mangling schemes, so that the user finds out that he's trying to mix code
- from different compilers, which is not likely to work because of the other
- problems.
-
- BTW, C has similar problems, although not to as large an extent. By
- default GCC uses a different mechanism for returning structure values from
- functions than most PCC-based C compilers. You have to remember to give
- GCC the -fpcc-struct-return option to force it to use the older convention
- (it's not used by default because it may be less efficient and
- non-reentrant). And if you have a program that must be linked with two
- libraries, one of which was compiled with the PCC convention and the other
- with GCC's default, you could be screwed.
- --
- Barry Margolin
- System Manager, Thinking Machines Corp.
-
- barmar@think.com {uunet,harvard}!think!barmar
-