James Kanze
11/16/2008 12:14:00 AM
On Nov 15, 6:04 pm, Paavo Helde <nob...@ebi.ee> wrote:
> shyam.lingego...@gmail.com kirjutas:
[...]
> > all. Is there any alternative for the same. What about
> > libraries compiled with two different compilers. If someone
> > can give some
> You probably mean whether you can link together C++ libraries
> compiled by different compilers. This is undefined by the
> standard, meaning that you cannot do this portably.
> It is only possible if both compilers follow the same ABI
> (application binary interface). The ABI is typically defined
> for a certain combination of a language platform, e.g. C++ ABI
> for Linux on x86_64. I believe there are some platforms with
> standardized C++ ABI, so if both compilers follow this, they
> should be able to talk to each other.
> However, this is not enough. For example, if one library uses
> small- string optimization for std::string and the other does
> not, then any attempt to pass a std::string from one library
> to another will most probably fail miserably. This is where
> the one-definition-rule of C++ kicks in, I guess - if the
> libraries are using different std::string definitions, the
> result is undefined.
The physical layout of std::string is part of a C++ ABI, so if
their is a C++ ABI, there should be no problem. (On the
platforms I work on, there isn't, and this doesn't work. In
fact, the C++ ABI even depends on compiler options, and you
can't necessarily link two libraries compiled with the same
compiler. From what I understand, this is more or less
general.)
> Using only C types and extern "C" functions may be helpful,
> because C ABI is standardized for more platforms. I am not too
> sure what the C ABI says about things like struct
> padding/packing, I would probably avoid them for any case and
> use arrays instead.
A C ABI must define how struct's are laid out. All that I know
do. (In particular, both Windows and Posix do, since both use
struct's in their system ABI.) Of course, a compiler still
might have options, or pragmas, to break this compatibility.
--
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