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, MSGID_SHORT autolearn=no autolearn_force=no version=3.4.4 Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!rutgers!clyde!wayback!arny From: arny@wayback.UUCP (Arny B. Engelson) Newsgroups: comp.lang.ada Subject: Re: Pre-elaboration Problems Message-ID: <1023@wayback.UUCP> Date: Mon, 5-Jan-87 17:25:06 EST Article-I.D.: wayback.1023 Posted: Mon Jan 5 17:25:06 1987 Date-Received: Mon, 5-Jan-87 23:59:51 EST References: <8701010253.AA21054@ucbvax.Berkeley.EDU> Organization: AT&T Bell Labs, Whippany, NJ Summary: A possible solution using a task List-Id: In article <8701010253.AA21054@ucbvax.Berkeley.EDU>, wilson%anchor.DECnet@lll-icdc.arpa ("ANCHOR::WILSON") writes: (Package spec here containing generic package with generic formal subprogram as one of the parameters, and a procedure within the generic package that is called by the subprogram supplied by the user as the actual to the generic). (main program contains declaration of subprogram to be passed, instantiation of generic package, then the body of the previously declared subprogram. Program_Error is raised because something in the instantiated generic invokes the user's subprogram before the body of the subprogram is elaborated). (two unsatisfactory solutions here). > My questions to the Ada community are these: > > o Is there a Solution 3? Yes, I think so. See my comments on the program below. > > o Can anyone make me feel better about Solutions 1 or 2? Solution 2 is better than solution 1. > > o How can I convince myself that my program isn't some day going > to call an unelaborated routine? Is there a simple checklist > I can use? Use careful design, keep reading the LRM, and hope the rules don't change too often. I've run into similar order-of-elaboration problems and have no checklist to offer. > Finally, why don't I get a PROGRAM_ERROR on the following program? It seems > like as soon as the main task has elaborated task T, T should start running > (given the higher priority) before P is elaborated . . . . > (I compiled and ran this using VAX Ada on a VAX 11/750.) > > with TEXT_IO; use TEXT_IO; > with SYSTEM; > procedure TEST_1 is > task T is > pragma PRIORITY( SYSTEM.PRIORITY'last ); > end T; > procedure P; > task body T is > begin P; end T; > procedure P is > begin PUT_LINE( "Hi!" ); end P; > begin null; end TEST_1; > > --- Rick Wilson > wilson%anchor.decnet@lll-icdc.arpa > (415) 423-6662 I believe the appropriate reference is LRM 9.3:2, which states: "activation of the task object starts after the elaboration of the declarative part (that is, after passing the reserved word BEGIN following the declarative part)". Therefore, task T doesn't begin executing until after the body of procedure P is elaborated. It would follow that you could solve the first problem by using a task to delay the execution of the instantiated package until everything was elaborated. Perhaps by encapsulating the instantiation of the generic within a task. I haven't the time to search for an exact solution, but I think this is a worthwhile direction to explore. Arny B. Engelson {bonnie|clyde|ihnp4}!wayback!arny AT&T Bell Laboratories, Whippany, N.J. (201) 386-4816