From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,9b05d372d1b25f25 X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!postnews.google.com!26g2000hsk.googlegroups.com!not-for-mail From: Ludovic Brenta Newsgroups: comp.lang.ada Subject: Re: Interfacing to C and types visible to Ada Date: Thu, 3 Jul 2008 05:58:37 -0700 (PDT) Organization: http://groups.google.com Message-ID: <465ba699-3dc8-4e73-a6cb-1f8dc691c27a@26g2000hsk.googlegroups.com> References: NNTP-Posting-Host: 153.98.68.197 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Trace: posting.google.com 1215089917 5534 127.0.0.1 (3 Jul 2008 12:58:37 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Thu, 3 Jul 2008 12:58:37 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: 26g2000hsk.googlegroups.com; posting-host=153.98.68.197; posting-account=pcLQNgkAAAD9TrXkhkIgiY6-MDtJjIlC User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.4.3) Gecko/20040924,gzip(gfe),gzip(gfe) Xref: g2news1.google.com comp.lang.ada:993 Date: 2008-07-03T05:58:37-07:00 List-Id: 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.