Skip to content
Hub Nexus

No author yetClaim it

Version 1Updated 2 min read

Support

Computing » Computer Science » Computer Programming » Ada Programming

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 — GNAT, for example, defines an interface to C++.

Interfacing with other languages is actually provided by pragma Export,

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.

with Ada.Text_IO;
with Interfaces.C;
with Interfaces.C.Pointers;
with Interfaces.C.Strings;

procedure ctest is
use Interfaces.C;

type int_array is array (size_t range <>) of aliased int with Pack;

package Int_Pointers is new Pointers (
Index => size_t,
Element => int,
Element_Array => int_array,
Default_Terminator => 0
);

-- int setupterm (char *term, int fildes, int *errret);
function Get_Terminal_Data (
terminal  : Interfaces.C.Strings.chars_ptr;
file_descriptor  : int;
error_code_pointer : Int_Pointers.Pointer
) return int
with Import => True, Convention => C, External_Name => "setupterm";

-- int tigetnum (char *name);
function Get_Numeric_Value (name : Interfaces.C.Strings.chars_ptr) return int
with Import => True, Convention => C, External_Name => "tigetnum";

function Format (value : int) return String is
result : String := int'Image (value);
begin
return (if result(1) = ' ' then result(2..result'Last) else result);
end Format;

error_code  : aliased int;
error_code_pointer : Int_Pointers.Pointer := error_code'Access;

begin
if Get_Terminal_Data (Interfaces.C.Strings.Null_Ptr, 1, error_code_pointer) = 0 then
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")))
);
else
Ada.Text_IO.Put_Line ("Can't access terminal data");
end if;
end ctest;

Child Packages

Interfaces.C
Interfaces.C.Extensions (GNAT)

Interfaces.OS2Lib.Errors (GNAT, OS/2)

Interfaces.VxWorks.IO (GNAT, VxWorks)

See also

Wikibook

Ada 95

Ada 2005

Where this page came from

This page was imported from Wikibooks. From “Ada Programming” on Wikibooks, by its contributors, under CC BY-SA 4.0. Changed here: set as a page; navigation and edit links left out; each image under its own licence, credited in its caption.

Nobody has written it yet — it is the source material at a new address, which is why search engines are asked to skip it and why no one earns from it. It is up for grabs: take it on, and it is yours to rewrite and to earn from.

Comments

Spinner Logo

Next in Ada Programming

CC BY-SA 4.0
[Computing]( » [Computer Science]( » [Computer Programming]( » [Ada Programming]( ## Forges of open-source projects [SourceForge]( Currently, there are more than 200 Ada projects hosted at SourceForge — including the example programs for [Ada Programming]( wikibook. [GitHub]( A source code repositor
CC BY-SA 4.0
Some of them are used as [attribute]( names. ## List of keywords | Ada Keywords | | | | | | --- | --- | --- | --- | --- | | abort | else | new | return | | | abs | elsif | not | reverse | | | abstract (Ada 95) | end | null | | | | accept | entry | | select | | | access | exception | of | separate |
CC BY-SA 4.0
Operators have arguments which in the RM are called Left and Right for binary operators, Right for unary operators (indicating the position with respect to the operator symbol). The list is sorted from lowest precedence to highest precedence. ### Logical operators [and]( and $x ∧ y$, (also keyword [
CC BY-SA 4.0
[Computing]( » [Computer Science]( » [Computer Programming]( » [Ada Programming]( This is an overview of the major features that are available in **Ada 2005**, the version of the Ada standard that was accepted by ISO in January 2007 (to differentiate it from its predecessors [Ada 83]( and [Ada 95](
CC BY-SA 4.0
[Computing]( » [Computer Science]( » [Computer Programming]( » [Ada Programming]( ## "Hello, world!" programs ### "Hello, world!" A common example of a language's [syntax]( is the [Hello world program]( Here is a straightforward Ada Implementation: File: hello_world_1.adb, Crate: basic ([view]( [pla
CC BY-SA 4.0
[Computing]( » [Computer Science]( » [Computer Programming]( » [Ada Programming]( Ada [compilers]( are available from several vendors, on a variety of host and target platforms. The [Ada Resource Association]( maintains a [list of available compilers]( Below is an alphabetical list of available comp