TITLE: Why not mix-n-match object files from different compilers? PROBLEM: tsai@vitsemi.com (Jodi Tsai) Are there any efforts underway to standardize the name mangling on all C++ compilers so software distributors don't have to ship separate object libraries for each C++ compiler they want to support? RESPONSE: clamage@Sun.COM (Steve Clamage), 23 Aug 94 This comes up so often it is a FAQ, but unfortunately isn't in the FAQ list. Name mangling is by far the smallest of the problems in object-code compatibility. The major reason name-mangling schemes are different is to help ensure that you don't mix object code from incompatible compilers. Some compatibility issues, but by no means an exhaustive list: 1. What is the EXACT layout of a class? Alignment requirements vary from machine to machine, so this can't be part of a language standard. Even on the same machine some compilers opt for space efficiency at the cost of time, and some opt for runtime speed at a cost in space. Some give you a choice (and if you mix modules compiled with different options your program won't run properly). 2. How are parameters passed to a function? On the stack? In registers? Some of each? Do floating-point values go in a special location? If so, always or only sometimes? Some machines don't have a stack and some don't have registers, so this can't be standardized. 2a. Are parameters passed left-to-right or right-to-left? If a stack is used, does it grow up or down? 3. How are structures passed to and returned from a function? On the stack? By reference to a copy made by the caller? By reference to the actual value which then must be copied by the called function? Where is the copy? 4. How is "this" passed to a member function? As the first parameter? As the last? In a special location not otherwised used? The answer to 2a above will probably affect this answer. 5. Constructors and destructors in general require extra hidden parameters apart from "this", to control construction and destruction of virtual base classes, and some other more obscure things too. EXACTLY what are these hidden parameters and how are they passed? Just what they are depends on other implementation decisions, so can't be standardized. Some platforms (machine and OS combinations) have a uniform specification for object code -- designated layout, alignment, and parameter-passing conventions, for example. This makes it easy to mix different languages in the same program. If a 3rd-party compiler vendor follows the conventions, you can also mix code from that vendor's compilers. In general, C++ is too new for such binary interface specifications to have fully developed. For one thing, new language features such as templates, exceptions, and namespaces, have required new implementation decisions which could not have been anticipated in any earlier attempt to standardize for a particular platform. At Sun, for example, we are in the process of publishing an "Application Binary Interface" which will describe all the C++ implementation decisions. Future compilers from Sun will adhere to this ABI. Other compiler vendors were invited to contribute to the ABI specification, and anyone who wants to will be able to make a compiler which generates code compatible with the future Sun compilers. Other platform vendors undoubtedly will also have ABI's as well. Everyone agrees that it makes life easier for library vendors and for users in general if object code can be freely mixed. The technical challenges are daunting, but many people are working on a solution, platform by platform.