Interfacing to Other Languages

Need: Ada and Other Languages, Not Ada or Others

Previous slide Contents Next slide

From the Script: Slide 23 - Interfacing to Other Languages

Ada 95 directly supports communication with applications developed in other languages through the use of Pragma Import and Pragma Export. [Ada 95 LRM 21.4] Specific pragmas are available for C, COBOL, and Fortran. Import Pragmas are intended primarily for accessing types and 'callback programs' written in other languages. Export pragmas allow mixed-language access to entities developed using Ada 95.

Pragma Import allows the developer to specify a subprogram in Ada 95, but utilize an algorithm developed in another language, as the body of the routine. For instance, a C routine to access a low level hardware component could be called via the Ada 95 Pragma Import.

Pragma Export allows development of an Ada 95 subprogram that is accessible by programs written in other languages.

The Ada 95 package Interfaces.C contain the pointers to variables, constants, and subprograms which allow an Ada program to communicate externally with other languages.

Package Interfaces is the parent of several library packages that declare types and other entities useful for interfacing to foreign languages. [Ada 95 LRM B.2] This package also contains some implementation-defined types that are useful across more than one language (in particular for interfacing to assembly language).

Interfaces.C - The facilities relevant to interfacing with the C language are provided by this package, its children and support for the Import, Export, and Convention pragmas. It contains the basic types, constants and subprograms that allow an Ada program to pass scalars and strings to C functions. [Ada 95 LRM B.3]

Interfaces.Fortran - The facilities relevant to interfacing with Fortran are the packages Interfaces.Fortran and support for the Import, Export and Convention pragmas with convention_identifier Fortran. [Ada 95 LRM B.5] The Interface.Fortran package defines Ada types whose representations are identical to the default representations of the Fortran intrinsic types: Integer; Real; Double Precision; Complex; Logical; and Character. These types can be used to pass objects between Ada and Fortran programs.

The To_Fortran and To_Ada functions map between the Ada type Character and the Fortran type Character_Set, and also between the Ada type String and the Fortran type Fortran_Character. The To_Fortran and To_Ada procedures are analogous to the string conversion subprograms found in Interfaces.COBOL.

Implementations may add additional declarations to support specific versions of Fortran (i.e., Fortran 77, Fortran 90)

Ada procedures correspond to Fortran subroutines. Ada functions correspond to Fortran functions.

Interfaces.COBOL - The facilities relevant to interfacing with COBOL are the packages Interfaces.COBOL and support for the Import, Export and Convention pragmas with convention_identifier COBOL. The COBOL interface package contains several sets of facilities:

A set of types corresponding to the native COBOL types of the supported COBOL implementation. This permits Ada data to be passed as parameters to a COBOL program.

A set of types and constants reflecting external data representations such as those found in files or databases. This permits COBOL-generated data to be read by Ada programs, and Ada-generated data to be read by COBOL programs. [Ada 95 LRM]

A generic package for converting between an Ada decimal value and either an internal or external COBOL representation.