comp.lang.ada
 help / color / mirror / Atom feed
From: stt@inmet.inmet.com
Subject: Re: how do I do pointers to functions i
Date: 4 Dec 89 15:39:00 GMT	[thread overview]
Message-ID: <20600024@inmet> (raw)
In-Reply-To: 23042@gryphon.COM


To call a subprogram, given only its address...

With some Ada compilers, it is possible to provide
an address clause for a pragma-interfaced subprogram
with a non-static address.  This means that the following
might work:

    procedure Real_Proc(B : Integer) is
    begin ... end Real_Proc;

. . .

    Proc_Addr : System.Address;

. . .

    Proc_Addr := Real_Proc'ADDRESS;

. . .

    procedure Dummy_Proc(B : Integer);
    pragma Interface(Ada, Dummy_Proc);
    for Dummy_Proc use at Proc_Addr;

. . .

    Dummy_Proc(42);

However, we have found that with most compilers we need to drop into
assembler to call a procedure given only its address.
This usually only requires a couple of lines of assembler.
For example:

    procedure Call_Ada_Proc(
      Param : Integer;
      Proc : System.Address
    );
    pragma Interface(Assembler, Call_Ada_Proc);

    . . .

    Call_Ada_Proc(42, Proc_Addr);

Depending on parameter passing conventions,
the code for Call_Ada_Proc can sometimes be a single
instruction which passes control to the address passed
as the last parameter.  By putting the address parameter
last, the earlier parameters are often already in the
"right" place (e.g. register or stack offset).

Since the address-clause "trick" is compiler-dependent
anyway, dropping into assembler is not a bad
alternative.  This is one of those
things we can hope will be solved as part of the Ada9X
process, since it seems like a common problem.
Of course, no guarantees...

S. Tucker Taft
Intermetrics, Inc.
Cambridge, MA  02138

  reply	other threads:[~1989-12-04 15:39 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1989-12-04  6:40 how do I do pointers to functions in Ada Michael Hunter
1989-12-04 15:39 ` stt [this message]
1989-12-06 13:44   ` how do I do pointers to functions i Ed Matthews
replies disabled

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