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,FREEMAIL_FROM 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!news1.google.com!Xl.tags.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local02.nntp.dca.giganews.com!nntp.comcast.com!news.comcast.com.POSTED!not-for-mail NNTP-Posting-Date: Thu, 03 Jul 2008 23:35:10 -0500 From: "Steve" Newsgroups: comp.lang.ada References: Subject: Re: Interfacing to C and types visible to Ada Date: Thu, 3 Jul 2008 21:36:45 -0700 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.3138 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3198 X-RFC2646: Format=Flowed; Original Message-ID: X-Usenet-Provider: http://www.giganews.com NNTP-Posting-Host: 24.20.111.206 X-Trace: sv3-8EPnY9u86O8epygr4a6cIxK05ZFz/LmSfLn5J1nb5Sgw/8KA+YIf2gSYN+aqrpNP/s9iuDO5n26Hid6!XtKVrZsU5jFQ1DelfZdzVjv3a6CfTrf3xyMabKD3FzJAmcPcc6SB/BDDXo6ONTuE+lDsAAq9/Bf3!y7pY7uGKGymB4//Tld3AgtL7QunDoQ== X-Complaints-To: abuse@comcast.net X-DMCA-Complaints-To: dmca@comcast.net X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.39 Xref: g2news1.google.com comp.lang.ada:1000 Date: 2008-07-03T21:36:45-07:00 List-Id: "Maciej Sobczak" wrote in message news:ff92d09d-5638-4422-ab11-d214529c0283@l64g2000hse.googlegroups.com... >I have a question related to interfacing to C, but I think it deserves > a new thread. > > 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. > > We can use Interfaces.C.int for binding Ada to C, but there is still a > need to expose somehow the type to regular Ada code. What type should > be used? > > Standard.Integer is the most natural choice, because it clearly > expresses the "domainless" character of the given type. On the other > hand, it might not be the same as Interfaces.C.int in terms of its > range. > When interfacing to C or to hardware, depending on the interface I usually take 1 of 2 approaches: 1) If data structures are being shared, I define records using representation clauses to ensure that the Ada and C representations match. 2) If simple arguments are being passed I tend to use Interfaces.Integer_n and Interfaces.Unsigned_n where n is usually either 8, 16, or 32. IMNSHO the interface should map exactly between the languages, no more, no less. If the C code only handles 32 bit integers, the Ada interface should do the same. If it is appropriate to define types that better abstract the interface, I do so in Ada and convert from the non-so abstract types in Ada. Regards, Steve (The Duck) > Interfaces.C.int might be a good choice as well, because it > "guarantees" (modulo what we have discussed in another thread) that > the information is transported correctly. The disadvantage is that it > is ugly and exposes implementation details which are not needed. > > The Ada wrapper library might also define its own type that will be > equivalent in range to Interfaces.C.int. What is the right name for > such a type? "Integer" is the best choice due to the character of this > type, but it collides with Standard.Integer. On the other hand, > packages are supposed to be the cure for such conflicts. > > What do you recommend? I would go for the last option: "Integer" > defined in the library's package. > > -- > Maciej Sobczak * www.msobczak.com * www.inspirel.com