From: Shark8 <onewingedshark@gmail.com>
Subject: Re: System.Address to Access to function/procedure conversion
Date: Sun, 28 Jul 2013 20:27:26 -0700 (PDT)
Date: 2013-07-28T20:27:26-07:00 [thread overview]
Message-ID: <30a1a22b-a003-4be5-a7c6-4fd5742d17fc@googlegroups.com> (raw)
In-Reply-To: <kt47f2$1vca$1@adenine.netfront.net>
On Sunday, July 28, 2013 4:54:27 PM UTC-6, Tarek Ghaleb wrote:
> On 2013-07-28, Shark8 wrote:
>
> >> 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)
>
> > Yes. It's actually absurdly easy. Here's a sample of how to do it in
> > Ada 2012, the same will work in earliet versions of Ada using
> > Pargmas... all the way back to 83, IIUC.
Oops; a little overzealous there.
You have to use attribute definition clauses, which IIRC came in Ada 95.
Below compiles and runs in GNAT using Ada83-mode:
-- Pragma Ada_2012;
Pragma Ada_83;
Pragma Assertion_Policy( Check );
With
Text_IO,
System;
Procedure Test is
Begin
Text_IO.Put_Line("Starting Test:");
ACTUAL_TEST:
declare
-- Note: Pragma CONVENTION is non-standard.
Procedure K;
Pragma Convention( C, K );
Procedure K is
begin
Text_IO.Put_Line( "K was called" );
end K;
Procedure Execute( Addr : System.Address ) is
-- Note: Pragma IMPORT is non-standard.
Procedure Stub;
Pragma Import( C, Stub );
-- Note: The Ada 83 LRM, 13.5 (Address Clauses) gives the following:
-- for CONTROL use at 16#0020#; -- assuming that SYSTEM.ADDRESS is an integer
-- with the following warning:
-- Address clauses should not be used to achieve overlays of
-- objects or overlays of program units. Nor should a given
-- interrupt be linked to more than one entry. Any program using
-- address clauses to achieve such effects is erroneous.
--
-- In Ada 95 we get propper Attribute Definition Clauses and so
-- we would use the following:
-- For Stub'Address Use Addr;
For Stub use at Addr;
Use Text_IO;
Begin
Put_Line( "Executing:" );
Put( ASCII.HT );
Stub;
End Execute;
begin
Execute( K'Address );
end ACTUAL_TEST;
Text_IO.Put_Line("Testing complete.");
End Test;
next prev parent reply other threads:[~2013-07-29 3:27 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
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 [this message]
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