comp.lang.ada
 help / color / mirror / Atom feed
From: "Adam Beneschan" <adam@irvine.com>
Subject: Re: Newbie question: Implementing a callback mechanism with Ada 83
Date: 12 Feb 2007 11:32:41 -0800
Date: 2007-02-12T11:32:41-08:00	[thread overview]
Message-ID: <1171308761.841427.26290@v33g2000cwv.googlegroups.com> (raw)
In-Reply-To: <1171230053.064136.26460@v33g2000cwv.googlegroups.com>

On Feb 11, 1:40 pm, "benibi...@gmail.com" <benibi...@gmail.com> wrote:

> By the way, a friend of mine whose is more experienced in Ada send me
> this mail which I wanted to share with you.
>
> ===========================================================
>
> "I can't claim to be an expert at Ada programming, and I usually use
> Ada95, so I may suggest a solution that is cannot be implemented in
> Ada83, but I have a few suggestions that you could try.
>
> 1. The solution to having no access-to-subprogram type in Ada83 is
> usually passing the address of the function around and then in Ada a
> function can be declared to 'use' that address as it's own like so:
>
> procedure Foo;
>
> procedure Install_Handler ( Event : Event_Type; Event_Handler :
> System.Address ) is
> begin
>   Event_Array(Event_Type) := Event_Handler;
> end Install_Handler;
>
> procedure Call_Handler ( Event : Event_Type ) is
>   procedure Temp;
>   for Temp use at Event_Array(Event);
> begin
>   Temp;
> end Call_Handler;

This may or may not work; as far as I know, it's going to depend on
your particular compiler vendor.  You might need to add an Interface
pragma, which may be called something different in different Ada
implementations (this was replaced by the Import pragma in Ada 95):

procedure Call_Handler (Event : Event_Type) is
   procedure Temp;
   pragma Interface (Ada, Temp);
   for Temp use at Event_Array(Event);
begin ...

If you just use the "use at", an Ada compiler *should* complain that
there's no body for Temp---the existence of a "for ... use at" isn't
supposed to be enough to tell the compiler that Temp's body will exist
somewhere else.  The Interface pragma should tell the compiler not to
expect a body.  However, this is a non-standard feature so there's no
telling what compilers may or may not allow that they technically
shouldn't have.

Basically, you'll probably have to check your compiler implementation
documentation or contact them and ask.  Or you can just experiment to
see if you can get the compiler to do what you want.

If it were me, I'd try to find out why Ada 83 is such a hard-and-fast
requirement---there isn't much downside to switching to Ada 95, as far
as I can tell, unless you're on one of those obsolete machines for
which the manufacturer never bothered to upgrade their Ada compiler to
Ada 95.

                              -- Adam




      parent reply	other threads:[~2007-02-12 19:32 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-02-10 19:38 Newbie question: Implementing a callback mechanism with Ada 83 benibilme
2007-02-10 20:40 ` Dmitry A. Kazakov
2007-02-11  2:46 ` Jeffrey R. Carter
2007-02-11 21:40   ` benibilme
2007-02-12  5:03     ` Jeffrey R. Carter
2007-02-12 19:32     ` Adam Beneschan [this message]
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox