[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
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] | [ ? ] |
Interfacing to C with GNAT can use one of two approaches:
Interfaces.C
may be used.
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
Additionally, there are the following general correspondences between Ada and C types:
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.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
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)
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.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Interfacing to COBOL is achieved as described in section B.4 of the Ada 95 reference manual.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
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] | [ ? ] |
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] | [ ? ] |