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=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,e9f44aef4f5aee18 X-Google-Attributes: gid103376,public From: "David C. Hoos, Sr." Subject: Re: Access to procedures Date: 1999/06/26 Message-ID: <0YarGl8v#GA.145@newstoo.hiwaay.net>#1/1 X-Deja-AN: 494111495 Content-Transfer-Encoding: 7bit References: <37737285.5CF9ED5F@Maths.UniNe.CH> Content-Type: text/plain; charset="iso-8859-1" MIME-Version: 1.0 Newsgroups: comp.lang.ada X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2314.1300 Date: 1999-06-26T00:00:00+00:00 List-Id: Gautier wrote in message news:37737285.5CF9ED5F@Maths.UniNe.CH... > Hello, Reference Manual gurus! > > I've encountered a stupid but sticky problem by implementing my > Unzip-Ada project. In the interactive versions of extract procedures, > I pass an access to a feedback procedure for display & interaction. > > *But* whatever the way I nest and subtype the things, the compiler > (GNAT) tells me (certainly with good reasons): > > "subprogram must not be deeper than access type" > > even when it doesn't seem depper at all! So, my question is: > how to do it ? The problem is that a compiler cannot know that your main procedure is always a main procedure -- i.e., that the feedback subprogram will have the same lifetime as the whole program. In other words, a nested subprogram exists only while the subprogram within which it is nested is executing. Even if the compiler could know that your main procedure is the main program, if the compiler follows the implementation advice of the RM in B.1 (39) (as gnat does), the main program no longer exists during the execution of adafinal -- so if any finalization code needed to call your feedback procedure, the feedback procedure would not exist. So to guarantee that a subprogram always exists (i.e., is callable via an access type), the subprogram must be declared at library level -- either as a subprogram declared in its own compilation unit, or within a package which itself is declared at library level -- i.e, where the package has a lifetime as long as the program. The package does not need to be an outer level package -- e.g., the package's specification could be declared within the specification of an outer level package. I hope this gives some insight into the problem.