Interfacing with other languages
From AdaCommons
- This article is a stub. You can help AdaCommons by expanding it.
Contents |
Using libraries in other languages (bindings)
Once you start using Ada, you may find that you want to use pre-existing libraries that are written in other languages. The following languages are supported by the Ada standard as part of the Interfaces packages:
- C
- C++
- COBOL
- Fortran
To use libraries in these languages, a binding must be created for that library. A binding is simply one or more packages that create a representation of the library that Ada can understand and interface to. The binding must have representations of each type and operation that must be used by Ada.
Before creating a binding to a library, you might check the directory of bindings to see if someone has already done the work for you. :)
Thick and thin bindings
There are two types of bindings. A thin binding is a representation that very closely matches the definitions of the types and operations of the native language, and the binding can be used in the same order that the native library would be used. The disadvantage to a thin binding is that the types used are not normal Ada types, but are usually types found in the Interfaces packages. Using thin bindings directly in programs usually requires a good deal of type conversion to and from Ada's more standard types and the types used in the binding.
Enter the thick binding. A thick binding is a representation of the library that looks and feels more like a native Ada library, and does any type conversions and any other processing required to give it that Ada-like feel. This is usually the preferred way to interface to external libraries, but takes more time and care.
Which binding is best?
The best practice in any but the most trivial library would be to create both thin and thick bindings. This offers the most flexibility and maintainability. The thick binding then serves as a wrapper that makes the thin binding more Ada-friendly.

