Ada Programming/Libraries/Interfaces

The Interfaces package helps in interfacing with other programming languages. Ada is one of the few languages where interfacing with other languages is part of the language standard. The language standard defines the interfaces for C, Cobol and Fortran. Of course any implementation might define further interfaces &mdash; GNAT, for example, defines an interface to C++.

Interfacing with other languages is actually provided by, and.

In Ada 2012 these clauses have an alternate form using "with" in place of "pragma."

Example
As an example, here is a complete program that queries the terminfo (terminal information) database on Unix systems to get the dimensions of the current terminal window. It interfaces with C language functions in the ncurses package, so it must be linked with ncurses (e.g. with the -lncurses switch) when it is compiled.

;  ;   ;   ;   ctest Interfaces.C;    int_array   (size_t  <>)   int  Pack; Int_Pointers  Pointers (      Index              => size_t,      Element            => int,      Element_Array      => int_array,      Default_Terminator => 0    ); Get_Terminal_Data (     terminal           : Interfaces.C.Strings.chars_ptr;       file_descriptor    : int;       error_code_pointer : Int_Pointers.Pointer    )  int Import => True, Convention => C, External_Name => "setupterm"; Get_Numeric_Value (name : Interfaces.C.Strings.chars_ptr) int Import => True, Convention => C, External_Name => "tigetnum"; Format (value : int) String result : String := int'Image (value); (if result(1) = ' ' then result(2..result'Last) else result); Format; error_code        :  int; error_code_pointer : Int_Pointers.Pointer := error_code'Access; Get_Terminal_Data (Interfaces.C.Strings.Null_Ptr, 1, error_code_pointer) = 0 Ada.Text_IO.Put_Line (       "Window size: " &        Format (Get_Numeric_Value (Interfaces.C.Strings.New_String ("cols"))) & "x" &         Format (Get_Numeric_Value (Interfaces.C.Strings.New_String ("lines")))      ); Ada.Text_IO.Put_Line ("Can't access terminal data"); ;  ctest;

Child Packages

 * Interfaces.C
 * Interfaces.C.Extensions (GNAT)
 * Interfaces.C.Pointers
 * Interfaces.C.Streams (GNAT)
 * Interfaces.C.Strings
 * Interfaces.CPP (GNAT)
 * Interfaces.COBOL
 * Interfaces.Fortran
 * Interfaces.OS2Lib (GNAT, OS/2)
 * Interfaces.OS2Lib.Errors (GNAT, OS/2)
 * Interfaces.OS2Lib.Synchronization (GNAT, OS/2)
 * Interfaces.OS2Lib.Threads (GNAT, OS/2)
 * Interfaces.Packed_Decimal (GNAT)
 * Interfaces.VxWorks (GNAT, VxWorks)
 * Interfaces.VxWorks.IO (GNAT, VxWorks)

Wikibook

 * Ada Programming
 * Ada Programming/Libraries
 * Ada Programming/Libraries/Standard
 * Ada Programming/Libraries/Ada
 * Ada Programming/Libraries/System

Ada 2005


|Interfaces

Programación en Ada/Unidades predefinidas/Interfaces