5

What is ABI, why doesn't C++ have a standard one, and why would it matter if it did?

Michael Petrotta
  • 59,888
  • 27
  • 145
  • 179
David
  • 27,652
  • 18
  • 89
  • 138
  • http://stackoverflow.com/questions/2171177/what-is-application-binary-interface-abi – T I Aug 03 '12 at 20:38
  • I can't say why it doesn't have one, but consider building a shared library compiled with mingw that has to be used in a visualc application. Because there's no standard that defines how parameters should be passed, visualc will push them on the stack in reverse as compared to mingw. – Radu Chivu Aug 03 '12 at 20:47
  • The reason why there isn't one for most platforms is simply that no one has proposed one. It doesn't happen by magic. – Bo Persson Aug 03 '12 at 21:06
  • also relevant: http://stackoverflow.com/questions/2083060/what-could-c-c-lose-if-they-defined-a-standard-abi – Cubbi Aug 03 '12 at 22:31

1 Answers1

4

ABI is an Application Binary Interface. It describes a standard for how application binaries are organized and accessed.

Standardization would allow multiple compilers to build binaries that were completely compatible with each other, or potentially allow single executables to run on various platforms without recompilation, etc.

Reed Copsey
  • 554,122
  • 78
  • 1,158
  • 1,373
  • I think I know what you mean by the last one, but the way it's phrased it's misleading... you can't run the *same* binary on different platforms. :\ – user541686 Aug 03 '12 at 20:37
  • @Mehrdad: yes you can, provided these platforms provide the same subset of the syscall interface that the application uses and the same library APIs. (E.g. FreeBSD implements a "Linux compatibility layer" to be able to execute some (not all) Linux binaries.) – Giel Aug 03 '12 at 20:40
  • @Mehrdad It depends on the level of ABI. With a complete operating system level ABI, you can do this (provided the necessary libraries and dependencies are also present) – Reed Copsey Aug 03 '12 at 20:41
  • There is no CPU architecture that is considered superior and that all people would agree upon using and give up everything else. Same for operating systems. And so there is no standard ABI. –  Aug 03 '12 at 20:42
  • Oh... I guess I was thinking "architecture" (CPU) instead of platform, my bad. >_< Maybe say "operating system" instead of "platform" to clarify? – user541686 Aug 03 '12 at 20:42
  • What files use a compiler-defined ABI specifically? objs, libs, dlls, exes? – David Aug 03 '12 at 20:54
  • @Dave Well, everything - but they're compiler/OS specific in C++. Each compiler tends to have it's own library, name mangling, etc. – Reed Copsey Aug 03 '12 at 20:56
  • So with a standardized ABI library's could just give out .libs and it would just work in any C++ compiler? – David Aug 03 '12 at 21:00
  • @Dave Yes. If you've seen other languages/frameworks, this is one huge disadvantage with C++. For example, .NET assemblies written on Windows work on Mono *unchanged* (provided they're not calling into platform-specific native code or using unavaiable libraries), since the CIL effectively defines a common ABI (which even works on other platforms). – Reed Copsey Aug 03 '12 at 21:01