From: Tarek Ghaleb <invalid@invalid.org>
Subject: Re: System.Address to Access to function/procedure conversion
Date: Sun, 28 Jul 2013 19:05:44 +0000 (UTC)
Date: 2013-07-28T19:05:44+00:00 [thread overview]
Message-ID: <kt3q27$18qs$1@adenine.netfront.net> (raw)
In-Reply-To: 15i0rfwzpj7cy$.ob5l4ffr5iqa$.dlg@40tude.net
On 2013-07-28, Dmitry A. Kazakov <mailbox@dmitry-kazakov.de> wrote:
> If you pass anything to C you should better keep it under C convention,
> even if you are certain that C does not touch it. You should pass an
> access-to-procedure/function to C and get it back. The access type will
> have pragma Convention (C, ... set. You don't need address here. E.g.
I agree completely. Using C convention is the way to do it. But is it
*possible* to call a function using its address? (even if not a such a
great idea)
But let me explain how this question came about:
I've been experimenting with writing a thick binding for FLTK for a
couple of days now, just exploring the idea (which deserves a thread
by itself, since it would be interesting to get some
feedback). Anyway, one thing I started working on was callbacks, If I
use C convention the user of the binding will also have to declare his
procedure using C convention. For example (simplified)
procedure Cb_Button;
pragma Convention (C, Cb_Button); -- This is required I guess
and then later register the callback with
Btn.Callback(Cb_Button'Access);
But if I remove
pragma Conversion (C, Cb_Button);
I get
...: subprogram "Cb_Button" has wrong convention
...: does not match convention of access type
But I don't want the user to worry about using pragma Convention for
every defined callback procedure or think in terms of interfacing with
C (or in FLTK's case C++). Ideally, Callback() is not the actual
imported callback() but it takes Ada friendly parameters and does any
type conversions needed then calls the imported callback() function. I
thought maybe it works like above but without the convention line and
then Callback() would send the Address instead of the Access to the
actual callback(). But maybe there is a better way to do it.
There are other issues of course, for example: callbacks do take
parameters and some are void* but that would complicate my question
for the time being.
Tarek.
--
For fools rush in where angels fear to tread. -- Alexander Pope
--- news://freenews.netfront.net/ - complaints: news@netfront.net ---
next prev parent reply other threads:[~2013-07-28 19:05 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-07-28 15:27 System.Address to Access to function/procedure conversion Tarek Ghaleb
2013-07-28 16:14 ` Dmitry A. Kazakov
2013-07-28 19:05 ` Tarek Ghaleb [this message]
2013-07-28 19:23 ` Simon Wright
2013-07-28 22:03 ` Tarek Ghaleb
2013-07-28 20:03 ` Dmitry A. Kazakov
2013-07-28 21:13 ` Shark8
2013-07-28 22:54 ` Tarek Ghaleb
2013-07-29 3:27 ` Shark8
2013-07-29 7:06 ` Tarek Ghaleb
2013-07-28 17:19 ` Jeffrey Carter
2013-07-28 19:05 ` Tarek Ghaleb
2013-07-28 20:04 ` Jeffrey Carter
2013-07-28 21:31 ` Maciej Sobczak
2013-07-29 6:26 ` Tarek Ghaleb
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox