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=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!news.swapon.de!aioe.org!.POSTED!not-for-mail From: Victor Porton Newsgroups: comp.lang.ada Subject: Re: Convert between C "void*" pointer and an access Date: Thu, 12 Oct 2017 02:03:06 +0300 Organization: Aioe.org NNTP Server Message-ID: References: NNTP-Posting-Host: 8U0x309/ia0QUzusgm/krA.user.gioia.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit X-Complaints-To: abuse@aioe.org User-Agent: KNode/4.14.10 X-Notice: Filtered by postfilter v. 0.8.2 Xref: news.eternal-september.org comp.lang.ada:48435 Date: 2017-10-12T02:03:06+03:00 List-Id: Randy Brukardt wrote: > "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. "- What is your solution for Windows printing problems? - Do not print." I NEED to convert between access to tagged records (and access to class-wide types) and C void* pointers. I need this because it is C's way to pass objects by using void* and I need to pass Ada objects to C functions (not just C objects). See my other message where I developed a package which is likely to work with every Ada compiler (or hopefully even with every conforming Ada compiler possible). -- Victor Porton - http://portonvictor.org