comp.lang.ada
 help / color / mirror / Atom feed
From: Ludovic Brenta <ludovic@ludovic-brenta.org>
Subject: Re: Interfacing to C and types visible to Ada
Date: Thu, 3 Jul 2008 05:58:37 -0700 (PDT)
Date: 2008-07-03T05:58:37-07:00	[thread overview]
Message-ID: <465ba699-3dc8-4e73-a6cb-1f8dc691c27a@26g2000hsk.googlegroups.com> (raw)
In-Reply-To: ff92d09d-5638-4422-ab11-d214529c0283@l64g2000hse.googlegroups.com

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.



  parent reply	other threads:[~2008-07-03 12:58 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-07-03 12:32 Interfacing to C and types visible to Ada Maciej Sobczak
2008-07-03 12:52 ` Georg Bauhaus
2008-07-03 12:58 ` Ludovic Brenta [this message]
2008-07-03 14:33 ` Robert A Duff
2008-07-03 19:19 ` tmoran
2008-07-03 19:35 ` Keith Thompson
2008-07-03 20:35   ` Maciej Sobczak
2008-07-05 20:08     ` Fionn Mac Cumhaill
2008-07-04  4:36 ` Steve
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox