Question

It seems to me that C libraries almost never have issues mixing libraries compiled with different versions or (sometimes) even different compilers, and that many languages seem to be able to interface with C libraries either directly or with minimal effort.

Is this all because the ABI is standard?

Was it helpful?

Solution 3

The ABI is defined by the Operatingsystem and/or the toolchain and is not defined by the standard. It defines for example how params are passed to a function call. What layout the stackframe has or how system calls are invoked.

The reason why most languages are able to interface with C libraries is most likely because most operating systems are (more or less) written in C, exposing C libraries as API and define a ABI based on that. And if a library written in a certain language wants to interface a specific OS, it has to be able to interface the ABI of this OS.

OTHER TIPS

ABIs are not codified in the language standard. You can get a copy of any of the C standard drafts to see it yourself.

And there's a good reason for ABIs not being in the standard. The standard cannot anyhow foresee all hardware and OSes for which C compilers can be implemented.

The ABI is most definitely not standard. At least, not in the C standard. Each operating system or tool chain specifies these things, but the language itself does not. Try running a windows program on a Linux machine, for example.

ABI is not a part of C standard. However, there had been efforts to standardize ABI. Quoting from "Linux System Programming" :

Although several attempts have been made at defining a single ABI for a given archi- tecture across multiple operating systems (particularly for i386 on Unix systems), the efforts have not met with much success. Instead, operating systems—Linux included—tend to define their own ABIs however they see fit.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top