Hi friends,
I came across a thread which said name mangling is the thing which makes C++ code to be re-compiled everytime when a different compiler is used..
Now my question is, when are the names mangled??? why are the names mangled?
Additionally, the acutal name mangling scheme isn't part standardised, so each compiler is free to use it's own scheme. But there are other reasons (such as the object file format) that requires code to be re-compiled across compilers.
Isnt it possible to standardise the object file format .. This way all the compilers irrespective of their implementation would produce the same kind of object file...!!
No. What the compiler produces is beyond the scope of the standard. This is a good thing, since it allows for interpreted implementations and things like that.
Well,, If java compiler can be made to produce same intermediate code representation that could be run by different JVMs, why cant C++ compiler output be made the same??
What do you mean by interpreted implementations?? U meant the object file is input to an interpretor that generates the ouput??
The JVM is why Java is so portable: it (although it may have a different overall structure per platform) always emulates only one machine, so I have no idea what the heck you meant by "different" JVMs. From the point of view of the program, they're all the same. I think you misunderstood something.
Well,, If java compiler can be made to produce same intermediate code representation that could be run by different JVMs, why cant C++ compiler output be made the same??
You're comparing apples and oranges. Java has a set of design goals different than that of C++.
What do you mean by interpreted implementations?
I mean the standard allows the language to be implemented by an interpreter, as opposed to a compiler. If the standard explicitly stated that the output must have a certain format, this would not be possible.
That's not the reason why the output is undefined, though. It's because the output of two different compilers will obviously be different if one targets x86 and the other targets ARM. And there's a myriad of other information included in an object file other than the code itself. Debugging information, resource files... If all that stuff was included in the standard, two things would happen: the Earth would run out of trees from printing copies of the standard and, worse still, it would be pointless because no one would implement those parts, anyway. One word: export. 'Nuff said.
Well,, I agree that java was for accomplishing different set of goals, but by coming up with such an object code standard, all the compilers would generate same object code and no recompilation would be necessaray across different compilers rite??
Yes, it's impossible. Giving the compiler the freedom to generate whatever the hell it feels like is not a bug in the design. It's a feature.
Compatible object formats can be figured out later, if necessary. For example, VC++ can read static libraries generated by MinGW. The real problem C++ has at the ABI level is name mangling, but that is unlikely to ever get fixed.