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 autolearn=unavailable autolearn_force=no version=3.4.4 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!goblin3!goblin.stu.neva.ru!news.netfront.net!not-for-mail From: Tarek Ghaleb Newsgroups: comp.lang.ada Subject: Re: System.Address to Access to function/procedure conversion Date: Mon, 29 Jul 2013 07:06:06 +0000 (UTC) Organization: Netfront http://www.netfront.net/ Message-ID: References: <15i0rfwzpj7cy$.ob5l4ffr5iqa$.dlg@40tude.net> <559b2a61-4e5e-4adf-a228-30506d255b08@googlegroups.com> <30a1a22b-a003-4be5-a7c6-4fd5742d17fc@googlegroups.com> NNTP-Posting-Host: 77.247.181.165 X-Trace: adenine.netfront.net 1375081566 32409 77.247.181.165 (29 Jul 2013 07:06:06 GMT) X-Complaints-To: news@netfront.net NNTP-Posting-Date: Mon, 29 Jul 2013 07:06:06 +0000 (UTC) User-Agent: slrn/1.0.1 (Linux) Xref: news.eternal-september.org comp.lang.ada:16598 Date: 2013-07-29T07:06:06+00:00 List-Id: On 2013-07-29, Shark8 wrote: > 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. > > 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; That's an _exhaustively_ thorough answer :-)) Actually, I've used For A'Address Use B'Address; before, but never thought of using it for a subprogram: the way you showed in the example above. Tarek. -- Rotten wood cannot be carved. -- Confucius, "Analects", Book 5, Ch. 9 --- news://freenews.netfront.net/ - complaints: news@netfront.net ---