From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.5-pre1 (2020-06-20) on ip-172-31-74-118.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-1.9 required=3.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.5-pre1 Date: 4 May 93 19:39:26 GMT From: cis.ohio-state.edu!pacific.mps.ohio-state.edu!zaphod.mps.ohio-state.edu!m agnus.acs.ohio-state.edu!usenet.ins.cwru.edu!cert.org!news.sei.cmu.edu!ajpo.sei .cmu.edu!progers@ucbvax.Berkeley.EDU (Pat Rogers) Subject: Re: Passing procedures as parameters to procedures. Message-ID: <1993May4.153926.11547@sei.cmu.edu> List-Id: Well, it isn't that you cannot do it at all, it just isn't portable (which it should be, of course, thus 9X), and restrictions do exist. In particular, the code that follows only works (on my compiler) for library unit level parameterless procedures. Certainly, on some implementations this approach won't work at all, due to restrictions regarding 'Address for subprograms (at least one always returns "address zero"). These restrictions are not universal by any means. The following is for Systems Designers 680X0 compilers: with system; package call_backs is subtype parameterless_procedure is system.address; procedure sign_in( caller : in parameterless_procedure ); procedure make_calls; end call_backs; with call_by_address; package body call_backs is callers : array(1..255) of parameterless_procedure; next : integer range 1 .. 255 := 1; procedure sign_in( caller : in parameterless_procedure ) is begin callers(next) := caller; next := next + 1; end sign_in; procedure make_calls is begin for K in 1 .. Next-1 loop call_by_address( callers(K) ); end loop; end make_calls; end call_backs; All well and good, you say, but what is this "call_by_address" procedure? It uses package Machine_Code to do a JSR to the desired routine, and uses an implementation-defined mechanism (the pragma) to associate the parameter (callee) with the register (A0) used in the JSR. Other implementations would use a different format for the JSR and for the parameter association mechanism... with System; with Machine_Code; procedure call_by_address( callee : in system.address ) is use Machine_Code; begin EA_INST'( Mode => A0_Indirect, Opcode => JSR ); end call_by_address; pragma Inline( Call_By_Address ); pragma Call_Sequence_Procedure( unit => call_by_address, parameter_types => (system.address), mechanism => ( Value (A0) ) );