From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.4 X-Received: by 10.224.137.137 with SMTP id w9mr46477568qat.6.1375068446908; Sun, 28 Jul 2013 20:27:26 -0700 (PDT) X-Received: by 10.50.101.110 with SMTP id ff14mr363170igb.9.1375068446874; Sun, 28 Jul 2013 20:27:26 -0700 (PDT) Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!news.eternal-september.org!news.eternal-september.org!feeder.eternal-september.org!usenet.blueworldhosting.com!feeder02.blueworldhosting.com!npeer01.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!cb17no999449qab.0!news-out.google.com!ce7ni0qab.0!nntp.google.com!cb17no999447qab.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Sun, 28 Jul 2013 20:27:26 -0700 (PDT) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=69.20.190.126; posting-account=lJ3JNwoAAAAQfH3VV9vttJLkThaxtTfC NNTP-Posting-Host: 69.20.190.126 References: <15i0rfwzpj7cy$.ob5l4ffr5iqa$.dlg@40tude.net> <559b2a61-4e5e-4adf-a228-30506d255b08@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <30a1a22b-a003-4be5-a7c6-4fd5742d17fc@googlegroups.com> Subject: Re: System.Address to Access to function/procedure conversion From: Shark8 Injection-Date: Mon, 29 Jul 2013 03:27:26 +0000 Content-Type: text/plain; charset=ISO-8859-1 X-Received-Bytes: 3348 Xref: news.eternal-september.org comp.lang.ada:16595 Date: 2013-07-28T20:27:26-07:00 List-Id: 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;