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.169.1 with SMTP id w1mr32829760qay.4.1375046002579; Sun, 28 Jul 2013 14:13:22 -0700 (PDT) X-Received: by 10.50.122.100 with SMTP id lr4mr118524igb.0.1375046002492; Sun, 28 Jul 2013 14:13:22 -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!news.bbs-scene.org!border4.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!cb17no209613qab.0!news-out.google.com!ce7ni0qab.0!nntp.google.com!cb17no285902qab.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Sun, 28 Jul 2013 14:13:22 -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> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <559b2a61-4e5e-4adf-a228-30506d255b08@googlegroups.com> Subject: Re: System.Address to Access to function/procedure conversion From: Shark8 Injection-Date: Sun, 28 Jul 2013 21:13:22 +0000 Content-Type: text/plain; charset=ISO-8859-1 Xref: news.eternal-september.org comp.lang.ada:16588 Date: 2013-07-28T14:13:22-07:00 List-Id: On Sunday, July 28, 2013 1:05:44 PM UTC-6, Tarek Ghaleb wrote: > On 2013-07-28, Dmitry A. Kazakov 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) 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. -- Used a declare-block for expedience; I had a test-bed file open. -- Be sure to WITH System. ACTUAL_TEST: declare Procedure K with Convention => C; Procedure K is begin Ada.Text_IO.Put_Line( "K was called" ); end K; Procedure Execute( Addr : System.Address ) is Procedure Stub with Import, Convention => C, Address => Addr; Begin Stub; End Execute; begin Execute( K'Address ); end ACTUAL_TEST; And there you are.