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.7 required=5.0 tests=BAYES_00,INVALID_DATE, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!uflorida!haven!vrdxhq!edm From: edm@vrdxhq.verdix.com (Ed Matthews) Newsgroups: comp.lang.ada Subject: Re: how do I do pointers to functions i Message-ID: <24077@vrdxhq.verdix.com> Date: 6 Dec 89 13:44:43 GMT References: <23042@gryphon.COM> <20600024@inmet> Reply-To: edm@vrdxhq.UUCP (Ed Matthews) Organization: Verdix Corporation HQ List-Id: In article <20600024@inmet> stt@inmet.inmet.com writes: > >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); The Verdix VADS compiler is an exception to the above. You can use a machine code insertion to do the same thing. We use this trick when passing function pointers to C code. with Machine_Code; with System; procedure Call( Function_Ptr : in System.Address; Param : in Integer_32) is procedure Do_Call(Param : in Integer_32) is use Machine_Code; begin ------------------------------------------- -- Stack is set up correctly so just do -- -- a branch to the start of the function -- ------------------------------------------- Code_1'(JMP, Function_Ptr'Ref); --------------------------------------------------------- -- JMP is an enumeration literal of type OP_CODE from -- -- package Machine_Code. The 'Ref attribute generates -- -- a reference to an Ada object. -- --------------------------------------------------------- end Do_Call; begin Do_Call(Param); end Call; -- Ed Matthews edm@verdix.com Verdix Corporation Headquarters (703) 378-7600 Chantilly, Virginia