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.
Interfacing to C with GNAT can use one of two approaches:
Interfaces.C
may be used.
Pragma Convention C
maybe 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
Long_Float
, i.e. as the C type double
.
Otherwise, it is a wider type which is also available as long
double
in GNU C.
Convention C
is specified, which causes them to have int
length. Without pragma Convention C
, Ada enumeration types map to
8, 16, or 32 bits (i.e. C types signed char, short, int respectively)
depending on the number of values passed. This is the only case in which
pragma Convention C
affects the representation of an Ada type.
type'Size
value in Ada.
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. Ada Core Technologies does not currently supply a suitable binding generator tool.
Using these pragmas it is possible to achieve complete inter-operability between Ada tagged types and C class definitions. See section Implementation Defined Pragmas for more details.
pragma CPP_Class ([Entity =>] local_name)
pragma CPP_Constructor ([Entity =>] local_name)
Import
) as corresponding to a C++ constructor.
pragma CPP_Vtable ...
CPP_Vtable
pragma can be present for each component of type
CPP.Interfaces.Vtable_Ptr
in a record to which pragma CPP_Class
applies.
Interfacing to COBOL is achieved as described in section B.4 of the Ada 95 reference manual.
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.
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.
Go to the first, previous, next, last section, table of contents.