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.8 required=5.0 tests=BAYES_00,INVALID_DATE autolearn=no autolearn_force=no version=3.4.4 Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!cs.utexas.edu!uunet!inmet!stt From: stt@inmet.inmet.com Newsgroups: comp.lang.ada Subject: Re: how do I do pointers to functions i Message-ID: <20600024@inmet> Date: 4 Dec 89 15:39:00 GMT References: <23042@gryphon.COM> Nf-ID: #R:gryphon.COM:23042:inmet:20600024:000:1539 Nf-From: inmet.inmet.com!stt Dec 4 10:39:00 1989 List-Id: 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