From: Victor Porton <porton@narod.ru>
Subject: Re: Convert between C "void*" pointer and an access
Date: Thu, 12 Oct 2017 02:03:06 +0300
Date: 2017-10-12T02:03:06+03:00 [thread overview]
Message-ID: <orm7v8$1gr$1@gioia.aioe.org> (raw)
In-Reply-To: orm663$pce$1@franka.jacob-sparre.dk
Randy Brukardt wrote:
> "Victor Porton" <porton@narod.ru> 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
> <anything-else>* 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
next prev parent reply other threads:[~2017-10-11 23:03 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-10-11 21:52 Convert between C "void*" pointer and an access Victor Porton
2017-10-11 22:32 ` Randy Brukardt
2017-10-11 23:03 ` Victor Porton [this message]
2017-10-12 7:57 ` Dmitry A. Kazakov
2017-10-12 8:05 ` Simon Wright
2017-10-29 14:50 ` David Thompson
2017-10-11 22:58 ` Victor Porton
2017-10-11 23:12 ` Victor Porton
2017-10-12 1:01 ` Victor Porton
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox