comp.lang.ada
 help / color / mirror / Atom feed
From: "Randy Brukardt" <randy@rrsoftware.com>
Subject: Re: Convert between C "void*" pointer and an access
Date: Wed, 11 Oct 2017 17:32:35 -0500
Date: 2017-10-11T17:32:35-05:00	[thread overview]
Message-ID: <orm663$pce$1@franka.jacob-sparre.dk> (raw)
In-Reply-To: orm3qe$1r0c$1@gioia.aioe.org

"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.

                                                Randy.


  reply	other threads:[~2017-10-11 22:32 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 [this message]
2017-10-11 23:03   ` Victor Porton
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