|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Interfacing to C and types visible to Ada
Maciej Sobczak wrote:
Imagine a C API that uses the int type to express something that does not have any dedicated domain. In other words, it is not "number of apples", not "height in meters", not "hotel room number", etc., it is just plain "integer", which meaning can depend on how the given library is actually used. How about making the Ada binding generic, e.g.: generic type Integer_Type is range <>; package Ada_Binding is function Foo return Integer_Type; end Ada_Binding; with Interfaces.C; package body Ada_Binding is function Foo return Integer_Type is function Internal return Interfaces.C.int; pragma Import (C, Internal, "foo"); begin return Integer_Type (Internal); end Foo; end Ada_Binding; This way, the user of the library specifies the particular meaning of the "integers" in each case. This design makes it possible to create several instances of Ada_Binding with different meanings and then benefit from Ada's strong typing. -- Ludovic Brenta. |
![]() |
| Viewing: Web Development Archives > FAQs > Programming > Interfacing to C and types visible to Ada |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|