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=-0.5 required=3.0 tests=BAYES_05,MSGID_SHORT autolearn=no autolearn_force=no version=3.4.5-pre1 Date: 27 Nov 91 16:48:01 GMT From: cis.ohio-state.edu!zaphod.mps.ohio-state.edu!unix.cis.pitt.edu!dsinc!gvlf 3.gvl.unisys.com!email!parkhill@ucbvax.Berkeley.EDU (parkhill) Subject: Re: Array of procedures? Message-ID: <5869@email.sp.unisys.com> List-Id: jonesm@nic.cerf.net (Matthew Jones) writes: > I know that there are arrays of task types and that is nice, > but is there also an array of procedure coonstruct, or > an array of package construct. Are there any good ways > of simulating arrays of the above without using tasks. > > Thanks in advance, > > Matthew Jones > jonesm@cerf.net I don't believe there is a "legal" way to create an array of procedures. However, in a desperate attempt to remove tasks from an Ada program I have in may life time created a pseudo array of "pointers" to procedures. Telesoft Ada does return a good value from 'Address of a procedure. You can save the address in a table and call the subprogram at a later time using its address. <> This is very dangerous, not portable, and not really a very good thing to do. A good self-respecting Ada programmer would NEVER do this!! Heres how to do it. Save the proc'address in an array. They better have all the same parameter type or you better know the parameters expected by the procedure. procedure Try_It ( Param : in Integer ); table(position) := Try_It'Address; To call the procedure go into a new scope containing a declaration of the subprogram. The declaration should EXACTLY match the original subprogram. Use the editor to grab the original declaration and paste if necessary. You will need to have visibility to all the types used by the subprogram. procedure Make_Call_By_Address is type Space_of_32_Type is range -2**31..2**31-1; for Space_of_32_Type'Size use 32; type Spacer_Type is record Space_of_32_Bits : Space_of_32_Type; Another_32_Bits : Space_of_32_Type; end record; for Spacer_Type'Size use 64; Top_Stack_Guard : Spacer_Type; Bottom_Stack_Guard : Spacer_Type; procedure Try_It ( Param : in Integer ); for Try_It use at table(position); PRAGMA Interface(Assembly, Try_It); begin -- Reference the variables so they are not optimized away. if (Bottom_Stack_Guard'Address = Top_Stack_Guard'Address) then raise Program_Error; -- This can never happen. end if; Try_It ( Param => 666 ); end; The pragma Interface fools the compiler into believing that the declaration is ok (BAD). The compiler will put the parameters onto the stack correctly. The unused local data items protect the stack from the pop of parameters by both the called subprogram and the calling subprogram (Kludge code if I ever saw it). As I have stated this Unsafe, Unwise, Bad Coding practice. Don't do it at home.