13.9. Interface to Other Languages


A subprogram written in another language can be called from an Ada program provided that all communication is achieved via parameters and function results. A pragma of the form

      pragma INTERFACE (language_name, subprogram_name);

must be given for each such subprogram; a subprogram name is allowed to stand for several overloaded subprograms. This pragma is allowed at the place of a declarative item, and must apply in this case to a subprogram declared by an earlier declarative item of the same declarative part or package specification. The pragma is also allowed for a library unit; in this case the pragma must appear after the subprogram declaration, and before any subsequent compilation unit. The pragma specifies the other language (and therby the calling conventions ) and informs the compiler that an object module will be supplied for the corresponding subprogram. A body is not allowed for such a subprogram (not even in the form of a body stub) since the instructions of the subprogram are written in another language.

This capability need not be provided by all implementations. An implementation may place restrictions on the allowable forms and places of parameters and calls.


      package FORT_LIB is 
        function SQRT (X : FLOAT) return FLOAT;
        function EXP  (X : FLOAT) return FLOAT;
        pragma INTERFACE(FORTRAN, SQRT);
        pragma INTERFACE(FORTRAN, EXP);
      end FORT_LIB;


The conventions used by other language processors that call Ada programs are not part of the Ada language definition. Such conventions must be defined by these other language processors.

The pragma INTERFACE is not defined for generic subprograms.

References: allow, body stub, compilation unit, declaration, declarative item, declarative part, function result, library unit, must, name, overloaded subprogram, package specification, parameter of a subprogram, pragma, subprogram, subprogram body, subprogram call, subprogram declaration.