3

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?

Baruch
  • 20,590
  • 28
  • 126
  • 201
  • Try combining library built with softfp ABI with application built with hard-float ABI on ARM machines. You'll be surprized. – aragaer Feb 14 '13 at 21:55
  • MinGW and MSVC compiles code often has trouble working together. http://www.mingw.org/category/wiki/msvc And the problem has been seen in plenty of other places too; the standard advice is to build everything with the same toolchain. – evil otto Feb 14 '13 at 21:59

4 Answers4

7

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.

Alexey Frunze
  • 61,140
  • 12
  • 83
  • 180
2

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.

Carl Norum
  • 219,201
  • 40
  • 422
  • 469
1

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.

junix
  • 3,161
  • 13
  • 27
  • Accepted because this is the only answer that explains why a C interface seems to be universally accessible. – Baruch Feb 17 '13 at 07:19
1

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.

gaganbm
  • 2,663
  • 3
  • 24
  • 36