Ada 编程/库/接口
外观
	
	
Interfaces 包有助于与其他编程语言进行接口。Ada 是少数将与其他语言的接口作为语言标准一部分的语言之一。语言标准定义了与 C、Cobol 和 Fortran 的接口。当然,任何实现都可能定义进一步的接口——例如,GNAT 定义了与 C++ 的接口。
实际上,与其他语言的接口由以下内容提供pragma Export,pragma Import 和pragma Convention.
在 Ada 2012 中,这些子句具有使用 "with" 代替 "pragma" 的替代形式。
例如,以下是一个完整程序,它查询 Unix 系统上的 terminfo(终端信息)数据库以获取当前终端窗口的尺寸。它与 ncurses 包中的 C 语言函数进行接口,因此它必须在编译时与 ncurses 链接(例如,使用 -lncurses 开关)。
withAda.Text_IO;withInterfaces.C;withInterfaces.C.Pointers;withInterfaces.C.Strings;procedurectestisuseInterfaces.C;typeint_arrayisarray(size_trange<>)ofaliasedintwithPack;packageInt_PointersisnewPointers ( Index => size_t, Element => int, Element_Array => int_array, Default_Terminator => 0 ); -- int setupterm (char *term, int fildes, int *errret);functionGet_Terminal_Data ( terminal : Interfaces.C.Strings.chars_ptr; file_descriptor : int; error_code_pointer : Int_Pointers.Pointer )returnintwithImport => True, Convention => C, External_Name => "setupterm"; -- int tigetnum (char *name);functionGet_Numeric_Value (name : Interfaces.C.Strings.chars_ptr)returnintwithImport => True, Convention => C, External_Name => "tigetnum";functionFormat (value : int)returnStringisresult : String := int'Image (value);beginreturn(if result(1) = ' ' then result(2..result'Last) else result);endFormat; error_code :aliasedint; error_code_pointer : Int_Pointers.Pointer := error_code'Access;beginifGet_Terminal_Data (Interfaces.C.Strings.Null_Ptr, 1, error_code_pointer) = 0thenAda.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"))) );elseAda.Text_IO.Put_Line ("Can't access terminal data");endif;endctest;
- Interfaces.C
- 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)
 
