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":
- A "direct" (also called "thin") binding
provides a one-to-one mapping to Ada
of whatever interface the foreign program provides.
Direct bindings are easy to understand if you understand the foreign
program's interface, and direct bindings for Ada are easy to create.
In particular, you can use the existing documentation, which is a very
important advantage for complex interfaces (like windowing systems).
Unfortunately, direct bindings are often a little clumsy to work with and
often don't provide the protection usually provided by Ada interfaces.
Thus, it's often nicer to work with "abstract" bindings.
- An "abstract" (also called "thick") binding provide a more
abstract, Ada-like view of the foreign program.
Unfortunately, while "abstract" bindings are nicer to work with, it takes
work and time to create the right abstractions.
Thus abstract bindings are harder to create.
Here are some other things you need to know about bindings:
- "Direct" and "abstract" are really extremes on a continuum;
there are bindings that are "mostly direct" but have been abstracted a
little, and there are "abstract" bindings that have some direct
one-to-one mappings.
- The terms "thick" and "thin" have other
related meanings (involving how a standard is written),
which is why I've used the terms "direct" and "abstract" here.
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 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.
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.
There are also tools to automatically generate direct (thin)
Ada bindings to C libraries.
Here are two tools (there are others as well):
- 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.
- 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?
- Direct ("thin") binding
- Abstract ("thick") binding
You may also:
Go back to the previous section
Skip to the next section
Go up to the outline of lesson 16
David A. Wheeler (wheeler@ida.org)