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: a07f3367d7,74bc23dcb20218db X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news3.google.com!feeder.news-service.com!85.214.198.2.MISMATCH!eternal-september.org!.POSTED!not-for-mail From: "Alex R. Mosteo" Newsgroups: comp.lang.ada Subject: Re: How to access this package written in C? Followup-To: comp.lang.ada Date: Mon, 03 May 2010 10:12:05 +0200 Organization: A noiseless patient Spider Message-ID: References: <4e9d2aaf-c0a6-4798-b838-8f5b7c4a39d1@k33g2000yqc.googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit Injection-Date: Mon, 3 May 2010 08:08:04 +0000 (UTC) Injection-Info: mx03.eternal-september.org; posting-host="w8g++bW4v3KH0+SqtoCNSw"; logging-data="5209"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/FYmXYNeKWlOyu2TZw0ZQj" User-Agent: KNode/4.4.2 Cancel-Lock: sha1:87p1dQ53A4UUJlOJC7qHQ5g5drk= Xref: g2news2.google.com comp.lang.ada:11300 Date: 2010-05-03T10:12:05+02:00 List-Id: Randy Brukardt wrote: > ... >>> I use this: >>> >>> subtype Void_Ptr is System.Address; >> >> I have sometimes used >> >> type Void is null record; >> pragma Convention (Void, C); >> type Void_Ptr is access all Void; >> pragma Convention (Void_Ptr, C); > > Most of the time, I've avoided any version of void* and simply written > overloadings for each type that I needed (using in out parameters if > possible, or access parameters if I needed the function result). That only > works of course when the number of types that you need is limited, and > it's not as flexible as some more direct mapping. > > But void* is exactly the opposite of strong typing, and it simply doesn't > fit well into the Ada type model. So avoiding it if possible is the best > approach. I've lived both ways, and I understand your point. In the particular case I had in mind, the C side changed too frequently for my own good, so using an opaque type and passing the pointer to it to C-side routines was the less maintenance-intensive approach. Massaging the C data returns into my own set of Ada types worked well, since the trick is hidden from user code. This reminds me of another thing that bores me about bindings, which is that even if you mimic C types with Ada types using convention C, these types are not always nice to propagate to client code, so in the end I find myself with even more duplicated types.