[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

10. Interfacing to Other Languages

The facilities in annex B of the Ada 95 Reference Manual are fully implemented in GNAT, and in addition, a full interface to C++ is provided.

10.1 Interfacing to C  
10.2 Interfacing to C++  
10.3 Interfacing to COBOL  
10.4 Interfacing to Fortran  
10.5 Interfacing to non-GNAT Ada code  


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

10.1 Interfacing to C

Interfacing to C with GNAT can use one of two approaches:

Pragma Convention C may be applied to Ada types, but mostly has no effect, since this is the default. The following table shows the correspondence between Ada scalar types and the corresponding C types.

Integer
int
Short_Integer
short
Short_Short_Integer
signed char
Long_Integer
long
Long_Long_Integer
long long
Short_Float
float
Float
float
Long_Float
double
Long_Long_Float
This is the longest floating-point type supported by the hardware.

Additionally, there are the following general correspondences between Ada and C types:


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

10.2 Interfacing to C++

The interface to C++ makes use of the following pragmas, which are primarily intended to be constructed automatically using a binding generator tool, although it is possible to construct them by hand. No suitable binding generator tool is supplied with GNAT though.

Using these pragmas it is possible to achieve complete inter-operability between Ada tagged types and C class definitions. See 1. Implementation Defined Pragmas, for more details.

pragma CPP_Class ([Entity =>] local_name)
The argument denotes an entity in the current declarative region that is declared as a tagged or untagged record type. It indicates that the type corresponds to an externally declared C++ class type, and is to be laid out the same way that C++ would lay out the type.

pragma CPP_Constructor ([Entity =>] local_name)
This pragma identifies an imported function (imported in the usual way with pragma Import) as corresponding to a C++ constructor.

pragma CPP_Vtable ...
One CPP_Vtable pragma can be present for each component of type CPP.Interfaces.Vtable_Ptr in a record to which pragma CPP_Class applies.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

10.3 Interfacing to COBOL

Interfacing to COBOL is achieved as described in section B.4 of the Ada 95 reference manual.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

10.4 Interfacing to Fortran

Interfacing to Fortran is achieved as described in section B.5 of the reference manual. The pragma Convention Fortran, applied to a multi-dimensional array causes the array to be stored in column-major order as required for convenient interface to Fortran.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

10.5 Interfacing to non-GNAT Ada code

It is possible to specify the convention Ada in a pragma Import or pragma Export. However this refers to the calling conventions used by GNAT, which may or may not be similar enough to those used by some other Ada 83 or Ada 95 compiler to allow interoperation.

If arguments types are kept simple, and if the foreign compiler generally follows system calling conventions, then it may be possible to integrate files compiled by other Ada compilers, provided that the elaboration issues are adequately addressed (for example by eliminating the need for any load time elaboration).

In particular, GNAT running on VMS is designed to be highly compatible with the DEC Ada 83 compiler, so this is one case in which it is possible to import foreign units of this type, provided that the data items passed are restricted to simple scalar values or simple record types without variants, or simple array types with fixed bounds.


[ << ] [ >> ]           [Top] [Contents] [Index] [ ? ]

This document was generated by Mail Server on June, 15 2005 using texi2html