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!news1.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!t-online.de!news.albasani.net!news.motzarella.org!motzarella.org!not-for-mail From: Keith Thompson Newsgroups: comp.lang.ada Subject: Re: Interfacing to C and types visible to Ada Date: Thu, 03 Jul 2008 12:35:16 -0700 Organization: None to speak of Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: reader.motzarella.org U2FsdGVkX19HeVVZuakN2p9Z98l1OemcfrBegVm+B2pBGlFmoTUyN/sszJuue/KjO1cGj7m0ovVgDGR5e6bUrAvxL/zB9S8MDmF+oIXRgbV8w8LRwuKHWXWZMajGKOBrVmyyLN0WqTA= X-Complaints-To: Please send complaints to abuse@motzarella.org with full headers NNTP-Posting-Date: Thu, 3 Jul 2008 19:35:18 +0000 (UTC) X-Auth-Sender: U2FsdGVkX1/lGM+WCDYDjX+9Lfr7GDms Cancel-Lock: sha1:x2H9BoDldW3+DKozCZkcppFIaoc= sha1:qtW1EJgaXKHCSAO78o/aY4Qfr6g= User-Agent: Gnus/5.1008 (Gnus v5.10.8) Emacs/21.3 (gnu/linux) Xref: g2news1.google.com comp.lang.ada:997 Date: 2008-07-03T12:35:16-07:00 List-Id: Maciej Sobczak writes: > 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. Yes, and that's a fatal flaw; I wouldn't even consider using Standard.Integer. What if your C API gives you a value outside the range of Standard.Integer? > 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. Re-using the name "Integer" is, IMHO, a really bad idea. Study the C API and come up with a description of what the type is actually used for. Then, for the Ada binding, declare a type or subtype with a name based on that description. Make it a subtype or derived type of Interfaces.C.int, so there's no risk of getting the range wrong. (Using a subtype has the advantage -- and the disadvantage -- of allowing it to be assigned to other objects of type Interfaces.C.int.) I'm not sure I understand this "domainless" business. Can you provide a simple example? -- Keith Thompson (The_Other_Keith) kst-u@mib.org Nokia "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister"