Section 16.3 - Ada Bindings

The previous material should help you develop a "binding" (interface) between software components, where one component is written in Ada and another component is written in another language. Naturally, it's easier if someone else or a tool does the job for you.

Before you can evaluate what someone else has done, you need to understand the major types of bindings between an Ada program and another program. These types are called "direct" and "abstract":

Here are some other things you need to know about bindings:

Now that you understand these basic issues, you can go hunt for ways to make this interfacing job easier. The Ada Information Clearinghouse maintains a list of source (including Ada bindings) and a document listing existing Ada bindings for other products and standards. Their list is incomplete, but it's a good starting point, especially for common products or standards such as POSIX, X windows, Microsoft Windows, or SQL databases. HBAP also maintains a list of existing Ada bindings. If you're interfacing with a commercial product, ask the vendor to supply you with an Ada interface. You could also post a request to comp.lang.ada if you can't find what you're looking for.

Here are some commonly-requested bindings:

  1. Win32 API. This is an interface for Microsoft Windows NT, Microsoft Windows 95, and OS/2; a subset of Win32 works under Microsoft Windows 3.1.
  2. X11Ada is an Ada 95 binding to Motif and X11 developed by Intermetrics. See the general listings given earlier for other X-related bindings and information.
  3. Relational databases generally use SQL as their query language. Although you can embed SQL queries in Ada as you can with other languages, a better approach is a specialized interface language that lets you really take advantage of both languages. There's an ISO standard (ISO/IEC 12227) of such a language, named SAMeDL. The SAMeDL specification, as well as a rationale for SAMeDL and notes on applications.
  4. An Ada binding to CORBA's IDL has been developed, enabling you to request and receive requests from other programs (written in arbitrary languages and located on arbitrary machines) via CORBA. You can learn more from the Ada bindings working group, and you can download the specification from the Object Management Group (OMG).

There are also tools to automatically generate direct (thin) Ada bindings to C libraries. Here are three tools (there are others as well):

  1. C2Ada translates C into Ada; it can handle complete programs, but its primary use has been to translate C header files into Ada to create Ada bindings. C2Ada was created as a major upgrade to Cbind (below). C2Ada is easy to use to create simple bindings, but it also provides many "hooks" (in the form of a configuration file) to support control on the translation process. C2Ada is available via Intermetrics.
  2. Cbind translates C declarations and C preprocessor definitions into Ada package(s). Its strength is in ease-of-use; just type:
       "cbind file.h > file.ads".
    
    Cbind is available via Rational and Walnut Creek.

  3. CtoAda translates declarations from C to Ada. CtoAda's strength is that it provides many "hooks" to allow a programmer to control the translation. This gives more control at the expense of requiring more work by the programmer.

Quiz:

If you want to quickly create a binding to another language and don't mind that it might be a little clumsy to use, what kind of binding would you create?

  1. Direct ("thin") binding
  2. Abstract ("thick") binding

You may also:

PREVIOUS Go back to the previous section

NEXT     Skip to the next section

OUTLINE  Go up to lesson 16 outline

David A. Wheeler (dwheeler@dwheeler.com)

The master copy of this file is at "http://www.adahome.com/Tutorials/Lovelace/s16s3.htm".