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=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,ec06888ca495a8ff X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news1.google.com!news.germany.com!newsfeed01.sul.t-online.de!t-online.de!newsfeed.arcor.de!newsspool1.arcor-online.net!news.arcor.de.POSTED!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: Newbie question: Implementing a callback mechanism with Ada 83 Newsgroups: comp.lang.ada User-Agent: 40tude_Dialog/2.0.15.1 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Reply-To: mailbox@dmitry-kazakov.de Organization: cbb software GmbH References: <1171136299.920852.179650@v33g2000cwv.googlegroups.com> Date: Sat, 10 Feb 2007 21:40:07 +0100 Message-ID: <1n74au9nwrn5q.7hxfg8xn4t8q.dlg@40tude.net> NNTP-Posting-Date: 10 Feb 2007 21:39:48 CET NNTP-Posting-Host: 8fb6c741.newsspool3.arcor-online.net X-Trace: DXC=I:^MZiZ]763McF=Q^Z^V384Fo<]lROoR1gUcjd<3m<;2A;PkK19L:T;[6LHn;2LCV>[ On 10 Feb 2007 11:38:19 -0800, benibilme@gmail.com wrote: > I need to develop an Ada application which must conform to Ada83. It > will be part of legacy system. I am very much new in Ada. The > application I have to develop is very much event driven. As an old > time C programmer I wanted to implement an event handling module which > you can subscribe callback functions and trigger the events when > necessary and unfortunately I have realized that Ada 83 does not > support pointer to subprograms. I have read about generics with which > defining subprograms as parameters of subprograms seems possible. On > the other hand, I could not figure out how to do it. > > I simply want to store function pointers to some data structure for > some certain events and call them with dynamic data when the event is > triggered. > > How can I do it in Ada 83 without the support of pointers to > subprograms. It is clear how to do this Ada95 as there is a direct > support for pointer to subprograms. > > Any help is much appreciated. I remember that once I used access-to-task to emulate access-to-subprogram. You can make handlers tasks and serve events in rendezvous. Another [tedious] possibility could be a proxy subprogram: type Call_Back_Id is (Foo_Id, Bar_Id, ...); procedure Call_Back (Id : Call_Back_Id, ) is begin case Id is when Foo_Id => Foo (); when Bar_Id => Bar (); ... end case; end Call_Back; In the data structure you store Id. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de