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=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!feeder.eternal-september.org!gandalf.srv.welterde.de!news.jacob-sparre.dk!franka.jacob-sparre.dk!pnx.dk!.POSTED.rrsoftware.com!not-for-mail From: "Randy Brukardt" Newsgroups: comp.lang.ada Subject: Re: Convert between C "void*" pointer and an access Date: Wed, 11 Oct 2017 17:32:35 -0500 Organization: JSA Research & Innovation Message-ID: References: Injection-Date: Wed, 11 Oct 2017 22:32:36 -0000 (UTC) Injection-Info: franka.jacob-sparre.dk; posting-host="rrsoftware.com:24.196.82.226"; logging-data="25998"; mail-complaints-to="news@jacob-sparre.dk" X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.5931 X-RFC2646: Format=Flowed; Original X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.7246 Xref: news.eternal-september.org comp.lang.ada:48432 Date: 2017-10-11T17:32:35-05:00 List-Id: "Victor Porton" wrote in message news:orm3qe$1r0c$1@gioia.aioe.org... > What is the right way to convert between C "void*" pointer and an access > to > a tagged or class-wide type? I doubt that there is a *right* way, there just are several possibilities. > Ada.Unchecked_Conversion seems to be what I need, but the access type may > be > "fat" and thus have another format than void*. Right, but not very likely. I'd expect this to work in most cases. But our solution in the Claw libraries was simply to use the appropriate C-convention access type in the interface definitions and avoid making any conversions at all. I believe that on the C side, void* and * have to use the same representation, so C convention should work properly for any pointer type. That is, if the C interface contains a void* parameter, we just used an appropriate C convention access type in its place in the Ada parameter definition. (Using overloading if we needed multiple such pointers - but that was very rare.) There's no counterpart to void* in Ada anyway, so one has to do something like that in the interfacing definitions. Randy.