comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: System.Address to Access to function/procedure conversion
Date: Sun, 28 Jul 2013 18:14:16 +0200
Date: 2013-07-28T18:14:16+02:00	[thread overview]
Message-ID: <15i0rfwzpj7cy$.ob5l4ffr5iqa$.dlg@40tude.net> (raw)
In-Reply-To: kt3d9j$vmp$1@adenine.netfront.net

On Sun, 28 Jul 2013 15:27:48 +0000 (UTC), Tarek Ghaleb wrote:

> As for why not just pass an Access to the function directly, the
> Address is actually passed to a C function which later passes it back
> to Ada.

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.

   type Func is access procedure (...);
   pragma Convention (C, Func);

   procedure C_Stuff (...; Call_Back_Ptr : Func; ...);
   pragma Import (C, C_Stuff, "fancy_c_library_entry");

The rationale is that, maybe unlikely still the access type might have a
different size than address and/or C pointer. When you use pragma
Convention (or the corresponding aspect if in Ada 2012) it is guaranteed to
work.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

  reply	other threads:[~2013-07-28 16:14 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 [this message]
2013-07-28 19:05   ` Tarek Ghaleb
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